cache4k icon indicating copy to clipboard operation
cache4k copied to clipboard

[Feature] Support listening to cache expiry

Open solonovamax opened this issue 3 years ago • 0 comments

In my application, I'd like to cache instances of an object which require to be shut down properly via a shutdown() method.

I want to cache them, since idk how expensive they are to instantiate and sometimes they might be used frequently for a bit, before not being needed for a while.

The only problem is, I can't add an eviction listener to the Cache. Something along the lines of

Cache.Builder.newBuilder()
        .expireAfterAccess(hours(4))
        .maximumCacheSize(50)
        .expiryListener { it -> it.shutdown }
        .build()

would be nice.

solonovamax avatar Aug 25 '21 22:08 solonovamax