2.0 Cache memory usage question

Showing 1-4 of 4 messages
2.0 Cache memory usage question John Langley 6/23/12 7:29 AM
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! 



Re: [play-framework] 2.0 Cache memory usage question Will Sargent 6/23/12 11:23 AM
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.
Re: [play-framework] 2.0 Cache memory usage question John Langley 6/25/12 5:45 PM
Thanks Will! I should have Read The Fine Manual ;^) 
Re: [play-framework] 2.0 Cache memory usage question virtualeyes 8/8/12 7:26 AM
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