Skip to content

Same key Expiring twice  #44

Description

@Ebrayan

same key is expiring twice with this config

val cache = Cache.Builder<String, String>()
        .maximumCacheSize(1_00)
        .expireAfterWrite(2.seconds)
        .expireAfterAccess(5.seconds)
        .eventListener { event ->
            when (event) {
                is CacheEvent.Created -> {}
                is CacheEvent.Updated -> {}
                is CacheEvent.Evicted -> {
                    scope.launch {
                        println("Evicted ${event.key}")
                    }
                }
                is CacheEvent.Expired -> {
                    scope.launch {
                        println("Expire ${event.key}")
                    }
                }
                is CacheEvent.Removed -> {
                    println("Evicted")
                }
            }
        }
        .build()

here I launch different coroutine adding value in the cache


for (n in 0..100) {
        delay(100)
        scopeL.launch {
            schemas.put("n$n", "some value")
            println("n$n")
        }
    }

Result

...
adding n18
 adding n19
 adding n20
Expire n0
Expire n2
Expire n1
Expire n0
Expire n1
Expire n2
 adding n21
Expire n3
Expire n3
 adding n22
Expire n4
Expire n4
 adding n23
Expire n5
Expire n5
 adding n24
Expire n6
Expire n6
 adding n25
...

The same keys are expiring twice

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions