【问题标题】:Caching in Grails? [closed]在 Grails 中缓存? [关闭]
【发布时间】:2012-12-17 15:05:30
【问题描述】:

对于使用 grails 实现缓存的好方法,是否有类似的最佳实践?应该使用哪些插件,应该缓存页面的哪些部分以及如何缓存?

【问题讨论】:

    标签: caching grails browser-cache grails-2.0


    【解决方案1】:

    大量问题取决于您的需要。要缓存域对象,您可以像这样使用 Hibernate 缓存:

    class Book {
        …
        static mapping = {
            cache true
        }
    }
    

    并在grails-app/conf/DataSource.groovy中配置Hibernate二级缓存:

    hibernate {
        cache.use_second_level_cache=true
        cache.use_query_cache=true
        cache.provider_class='org.hibernate.cache.EhCacheProvider'
    }
    

    Grails Documentationcaching guide

    您还可以基于Spring cache 使用Grails cache plugin 缓存您的控制器和服务:

    @Cacheable('message')
       Message getMessage(String title) {
          println 'Fetching message'
          Message.findByTitle(title)
       }
    

    您会找到出色的文档here

    如果你想缓存渲染页面,你也可以看看gsp template rendering cache plugin

    【讨论】:

      猜你喜欢
      • 2014-02-10
      • 2014-03-25
      • 2011-05-09
      • 2011-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      相关资源
      最近更新 更多