Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same key Expiring twice #44

Open
Ebrayan opened this issue Dec 30, 2023 · 0 comments
Open

Same key Expiring twice #44

Ebrayan opened this issue Dec 30, 2023 · 0 comments

Comments

@Ebrayan
Copy link

Ebrayan commented Dec 30, 2023

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

@Ebrayan Ebrayan closed this as completed Dec 31, 2023
@Ebrayan Ebrayan reopened this Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant