我在Grails应用程序中抛出了以下异常:
[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)
与Hibernate相关的DataSource
设置如下:
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}
似乎当前的缓存设置正在写入/tmp/tomcat6-tmp/
。
我想完全禁用缓存到磁盘,而只是缓存到内存。我该怎么做?
答案 0 :(得分:2)
如果类路径中没有ehcache.xml文件,ehcache将使用其默认设置。但是如果你有一个(把它放在grails-app / conf或src / java中)那么将使用它。 http://ehcache.org/ehcache.xml上的示例已有详细记录。
这样的事情应该有效;调整未显式声明的缓存的默认缓存设置(虽然我更喜欢为了文档而创建它们)并定义具有非默认设置的任何特定缓存:
<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>
将两个Hibernate缓存放在那里也是一个好主意,这样可以根据需要方便地调整它们。