简体   繁体   English

是否有grails方法来缓存grails域对象超时

[英]Is there a grails way to cache grails domain objects with a timeout

For tables which will never change for the rest of eternity, you can add this to a domain class: 对于永远不会改变的表,您可以将其添加到域类:

static mapping = {
    cache true
}

However, in real life, this is next to useless as all table change, even if its slowly. 然而,在现实生活中,随着所有表格的变化,即使它的速度很慢,这也是无用的。 Eg we have a currency and country table. 例如,我们有货币和国家表。 We read it with every request. 我们每次请求都会阅读它。

It is possible we add or remove currencies (eg if we no longer support them), or modify a country, but this may happen once a month or even a year. 我们可以添加或删除货币(例如,如果我们不再支持它们),或修改国家/地区,但这可能每月或甚至一年发生一次。 However, when it is modified, the new version HAS to be picked up with server restarts. 但是,当它被修改时,新版本HAS将在服务器重新启动时被选中。

Ie the cache has to have some sort of timeout, so it can refresh. 即缓存必须具有某种超时,因此它可以刷新。

Is there any plugin or solution to this for grails 3? grails 3有没有插件或解决方案?

Maybe a job which kicks off every hour, and some how gets the caches to re-read? 也许一个工作每小时开始,有些如何让缓存重新阅读?

Grails 3.3.8 (grails 4 is not an option currently) Grails 3.3.8(grails 4目前不是一个选项)

Knowing more about the app might affect the recommendation but a simple approach is to have a service configured with @Cacheable methods which return the relevant information (probably best not to cache the actual entity, but caching information in the entity is fine). 了解有关应用程序的更多信息可能会影响建议,但一个简单的方法是使用@Cacheable方法配置服务, @Cacheable方法返回相关信息(可能最好不要缓存实际实体,但实体中的缓存信息很好)。 You can evict/update the cache at whatever frequency or in response to whatever events in the app that you like. 您可以以任何频率逐出/更新缓存,或者响应您喜欢的应用程序中的任何事件。

https://grails-plugins.github.io/grails-cache/3.0.2/index.html https://grails-plugins.github.io/grails-cache/3.0.2/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM