-
Notifications
You must be signed in to change notification settings - Fork 120
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
Memory Leak!! with CaffeineCache #556
Comments
Resolving the issue with idea 1, 'When the cache key is expired, remove the key in the doGet()' probably is bad because if a 2 isn't great either, because I would expect my scalacache to behave the same regardless of what the underlying cache is. Perhaps a middle ground would be to add some settings to the |
I'm getting started with ScalaCache + Caffeine and I'm trying to understand the implications of this. I'm unclear as to whether the TTL on ScalaCache's |
@petersondrew The Really it boils down to when the memory is freed. As far as the |
What happened:
When the above Companion Object is used to instantiate
CaffeineCache
, a cache entry with TTL is not evicted by the underlyingCaffeine
even thoughCaffeineCache
sdoGet()
call returnsNone
after the TTL expiry.When the
CaffeineCache
returnsNone
, it makes the end user think as if the cache entry was evicted. But the entry is still present in the Heap and could not be garbage collected piling up Memory Usage as the underlyingCaffeine
is not set with any eviction policy.What you expected to happen:
When the CaffeineCache
doGet()
call returns None, the cache entry should either be evicted or should be evicted in the next maintenance run ofCaffeine
.How to reproduce it (as minimally and precisely as possible):
val caffeinecache = CaffeineCache[CacheDetails]
doPut()
call.doPut()
call.Anything else we need to know?:
Caffeine.newBuilder().build[String, Entry[V]]()
doesn't add any eviction policy by default. Hence, the cache entries remain in Heap even after TTL expiry.scalacache does provide another companion object interface where the underlying Caffeine Object can be passed by the end-user. To not encounter this issue, the Caffeine object can be created by the end-user with an appropriate eviction policy.
How can we resolve the issue?:
These are various ways I could think of. I am sure there could be better ways.
doGet()
call. The framework currently returnsNone
. Note: There could be performance implications with this approach in applications with heavy reads - not a good way to approach this issue.doPut()
call. Remove the second layer of expiry check inCaffeineCache
indoGet()
call. Take TTL as a parameter while instantiating CaffeineCache and set the TTL in the underlying Caffeine object. For more advanced users, we can take the APIs exposed byCaffeine
for implementing eviction policies as an Optional parameter and let Caffeine handle the eviction of the Key.The text was updated successfully, but these errors were encountered: