Skip to content

Commit

Permalink
Make cache expiration time configurable (#5076)
Browse files Browse the repository at this point in the history
  • Loading branch information
fe-lix- authored Mar 10, 2021
1 parent d8cf172 commit 00642f7
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ trait MultipleReadersSingleWriterCache[W, Winfo] {
/** Subclasses: Toggle this to enable/disable caching for your entity type. */
protected val cacheEnabled = true
protected val evictionPolicy: EvictionPolicy = AccessTime
protected val cacheExpirationTime: Long = 5
protected val cacheExpirationTimeUnit: TimeUnit = TimeUnit.MINUTES
protected val fixedCacheSize = 0

private object Entry {
Expand Down Expand Up @@ -452,8 +454,8 @@ trait MultipleReadersSingleWriterCache[W, Winfo] {
.softValues()

evictionPolicy match {
case AccessTime => b.expireAfterAccess(5, TimeUnit.MINUTES)
case _ => b.expireAfterWrite(5, TimeUnit.MINUTES)
case AccessTime => b.expireAfterAccess(cacheExpirationTime, cacheExpirationTimeUnit)
case _ => b.expireAfterWrite(cacheExpirationTime, cacheExpirationTimeUnit)
}

if (fixedCacheSize > 0) b.maximumSize(fixedCacheSize)
Expand Down

0 comments on commit 00642f7

Please sign in to comment.