EhCache default parameters

11 views
Skip to first unread message

Tim Brigginshaw

unread,
Sep 28, 2016, 4:54:49 AM9/28/16
to Play Framework
Hi,

It seems to me that the code in EhCacheApi, together with the default from AsyncCaheApi conspire to hide the values of timeToLive and timeToIdle from the ehcache.xml configuration file.


def set(key: String, value: Any, expiration: Duration = Duration.Inf): Future[Done]

def set(key: String, value: Any, expiration: Duration): Future[Done] = {
   val element = new Element(key, value)
   expiration match {
     case infinite: Duration.Infinite => element.setEternal(true)
     case finite: FiniteDuration =>
       val seconds = finite.toSeconds
       if (seconds <= 0) {
         element.setTimeToLive(1)
       } else if (seconds > Int.MaxValue) {
         element.setTimeToLive(Int.MaxValue)
       } else {
         element.setTimeToLive(seconds.toInt)
       }
   }
   Future.successful {
     cache.put(element)
     Done
   }
 }

TimeToLive can be set on an element by element basis, but timeToIdle cannot  - and appears to default to 0 (no time to idle) instead of the value in the config (although I cannot see where this happens explicitly)

It would be nice in a future version of Play  to have a way of using all the values in ehcache.xml out of the box without having to write a new cache module.

Thanks

Tim Brigginshaw
Computer Scientist, EPFL
Reply all
Reply to author
Forward
0 new messages