开发者

"Could not remove disk store entry for [Class]" in Grails - how do I disable disk based caching?

I'm getting the following exception thrown in my Grails application:

[1564928] store.DiskStore ClassNameCache: Could not remove disk store entry for ClassName#123195371. Error was null
java.io.EOFException
       at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2297)
       at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:开发者_如何转开发2766)
       at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:797)
       at java.io.ObjectInputStream.<init>(ObjectInputStream.java:297)
       at net.sf.ehcache.store.DiskStore$1.<init>(DiskStore.java:316)
       at net.sf.ehcache.store.DiskStore.loadElementFromDiskElement(DiskStore.java:316)
       at net.sf.ehcache.store.DiskStore.expireElements(DiskStore.java:973)
       at net.sf.ehcache.store.DiskStore.throwableSafeExpireElementsIfRequired(DiskStore.java:657)
       at net.sf.ehcache.store.DiskStore.spoolAndExpiryThreadMain(DiskStore.java:645)
       at net.sf.ehcache.store.DiskStore.access$900(DiskStore.java:68)
       at net.sf.ehcache.store.DiskStore$SpoolAndExpiryThread.run(DiskStore.java:1110)

The DataSource settings related to Hibernate are the following:

hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}

It seems like the current caching setup is writing to /tmp/tomcat6-tmp/.

I would like to completely disable caching to disk and instead only cache to memory. How do I do that?


If you don't have an ehcache.xml file in your classpath, ehcache uses its default settings. But if you do have one (put it in grails-app/conf or src/java) then that will be used instead. The example at http://ehcache.org/ehcache.xml is well documented.

Something like this should work; tweak the default cache settings for caches that aren't explicitly declared (although I prefer to create them all for documentation sake) and define any specific caches that have non-default settings:

<ehcache>

   <diskStore path='java.io.tmpdir' />

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

   <cache name='com.yourcompany.yourapp.DomainClassName'
      maxElementsInMemory='1000'
      overflowToDisk='false'
   />

   <!-- hibernate stuff -->
   <cache name='org.hibernate.cache.StandardQueryCache'
      maxElementsInMemory='50'
      eternal='false'
      timeToLiveSeconds='120'
      maxElementsOnDisk='0'
   />

   <cache name='org.hibernate.cache.UpdateTimestampsCache'
      maxElementsInMemory='5000'
      eternal='true'
      maxElementsOnDisk='0'
   />

</ehcache>

It's also a good idea to put the two Hibernate caches in there so they can be conveniently adjusted as needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜