开发者

Hibernate cache in grails domain class

I have a domain class in grails 1.5 that represents data from a table that seldom changes. How can I configu开发者_Python百科re hibernate's cache so the class accesses the table let's say only once per hour?

Thanks


Drop an ehcache.xml into grails-app/conf. You can take one, for instance, from %grails_home%/lib/ehcache-core-XXX.jar, ehcache-failsafe.xml.

In defaultCache tag, put in timeToLiveSeconds="3600".

Though, cache won't give you an absolute guarantee - for instance, it won't pre-cache, and some instances can be pushed out.

EDIT: In case you're interested in per-class caching strategy, a sample:

<cache name="org.appfuse.model.User"
    eternal="false"
    timeToIdleSeconds="3600"
    timeToLiveSeconds="3600"
    overflowToDisk="false" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜