ehcache.xml을 사용하여 캐시 동작을 구성 할 수 있습니다. 캐시가없는 경우 캐시는 기본값으로 구성되지만 사용하면 캐시가 대신 사용됩니다. grails-app/conf
에 넣으면 클래스 패스에 복사됩니다.
가정 도메인 클래스는 폐기되지 않도록 당신은 캐시와 = 진정한 영원한 설정하는 요소의 수를 지정할 수 있습니다 com.yourcompany.yourapp.YourDomainClass
입니다 :
<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.YourDomainClass'
maxElementsInMemory='10000'
eternal='true'
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>
구성하는 방법에 대한 자세한 내용은 ehcache.xml
는 http://ehcache.org/ehcache.xml을 볼 수있는 코멘트에 많은 문서가 있습니다.
그 일을하는 데, 당신의
BootStrap.groovy
은 다음과 같이 보일 것이다 :
import com.yourcompany.yourapp.YourDomainClass
class BootStrap {
def init = { servletContext ->
def ids = YourDomainClass.executeQuery('select id from YourDomainClass')
for (id in ids) {
YourDomainClass.get(id)
}
}
}
는 각 인스턴스에 대한 get()
라고하는 데, get()
향후 호출은 2 레벨 캐시를 사용합니다.
'Bootstrap.groovy'의 코드를'YourDomainClass.list()'로 대체 할 수 있습니까? –
감사합니다. 이것은 잘 작동하는 것 같습니다. – pieterk