question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Eviction listener

See original GitHub issue

Similar to #38, it would be really useful to have an eviction listener.

In my use-case i’m using an in-memory Cache<MyKey, File> to manage an on-disk cache of files, so whenever an entry is expired / removed / evicted from the cache I need to delete the corresponding file.

I’m currently using caffeine but would like to try cache2k to see if it supports our access patterns better.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
cruftexcommented, Apr 3, 2017

Thanks for the detailed thoughts on this. Looks reasonable.

so if it was possible to expose the intrinsic age of each item to the cache

cache2k honors the least recently used aspect. So when you insert the oldest ones first, that will do.

I plan to release 1.0 now with the current feature set. Then I like to start an 1.1 dev version. This allows testing new features, while being able to change and improve the API or even drop features again that didn’t prove. I cannot promise, but probably something testable will pop up the next months. Would be nice when you then take a look at it and test it.

0reactions
cr-orilibhabercommented, Apr 27, 2020

Well, I took 1.3.1 for a test drive and I admit it looks mostly promising, the thing is, I noticed that the eviction Listener invocation was flaky, it either is able to work flawlessly, or not at all. I’ll expand on this: I use a messaging service to deliver events to a SpringBoot based service. I use Cache2K as a read-through cache (LRU) to load results from a DB, it is instantiated lazily, manually (not through Spring’s DI) as this is a multi-tenant service and the key set variations are unknown. I test the LRU capability of the cache by using a maxSize limit of 1 to trigger eviction constantly (I use a key set > 3) When the message queue is empty, and the whole service is given enough time to start (along with Cache2K instance) the eviction Listener is able to intercept evicted events once traffic start coming in. But when I start the service and the queue has already pending messages that start coming in as soon as the consumer thread is ready, it seems like Cache2K instance didn’t had “enough time” to start-up correctly and as a result the eviction Listener doesn’t get invoked at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EntryEvictedListener (Hazelcast Root 4.0 API)
Interface EntryEvictedListener<K,V> ... Invoked upon eviction of an entry. Implementations of this interface receive events after removal of the entry. Removals ...
Read more >
How to use eviction, listeners, and statistics in Guava Cache
Guava Cache provides flexibility to add removal listeners to take action on eviction of keys from the cache. In the below code, notification.getCause()...
Read more >
EvictionListener (Infinispan JavaDoc All 9.4.24.Final API)
Eviction listener that is notified when entries are evicted from the underlying container due to the given eviction policy. Since: 9.0; Author: wburns ......
Read more >
Distributed Object Events
EntryExpiredListener : It is notified when an entry is removed from the map due to expiration-based eviction (happens when time-to-live and/or maximum idle ......
Read more >
RemovalListeners (Guava: Google Core Libraries for Java ...
Returns a RemovalListener which processes all eviction notifications using executor . Parameters: listener - the backing listener: executor - the executor ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found