cache4k
cache4k copied to clipboard
[Feature] Support listening to cache expiry
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.