2.0 Cache memory usage question

603 views
Skip to first unread message

John Langley

unread,
Jun 23, 2012, 10:29:47 AM6/23/12
to play-fr...@googlegroups.com
Cache newbie question about how the default Play Cache implementation manages it's memory.

If I put a value in the cache, should I clean it out at some point? Put another way,  will it be a memory leak if I don't clear it or will EHCache flush the old values as it needs memory on an LRU (or some other strategy) basis? 

Thanks! 



Will Sargent

unread,
Jun 23, 2012, 2:23:35 PM6/23/12
to play-fr...@googlegroups.com
So from

http://www.playframework.org/documentation/2.0/ScalaCache

It doesn't mention a timeout. Looking at the code

https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/cache/Cache.scala

It just does a straight CacheManager.create() from EhCache, which uses
the default configuration, defined here:

https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/resources/ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"
updateCheck="false">

<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>

</ehcache>

So it looks like it times out after 2 minutes if you don't touch it.

Will.

John Langley

unread,
Jun 25, 2012, 8:45:03 PM6/25/12
to play-fr...@googlegroups.com
Thanks Will! I should have Read The Fine Manual ;^) 

virtualeyes

unread,
Aug 8, 2012, 10:26:08 AM8/8/12
to play-fr...@googlegroups.com
What you say is true, to a degree; if you read further down:
https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/cache/Cache.scala#L149

and then:
https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/cache/Cache.scala#L17

affirms it.

You'll see that not specifying a timeout value means it never times out; i.e. the underlying default 2 minute timeout does not come into play since setEternal flag is set to true.

The Play 2.0 scala documentation does not seem to mention this, however:
https://github.com/playframework/Play20/wiki/Scalacache
Reply all
Reply to author
Forward
0 new messages