【问题标题】:Jhipster : Why cache is not working?Jhipster:为什么缓存不起作用?
【发布时间】:2016-10-29 17:02:19
【问题描述】:

我正在研究 Jhipster 项目的缓存。我想在用户实体上使用缓存。

@Entity
@Table(name = "jhi_user")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class User extends AbstractAuditingEntity implements Serializable {
// attributes, getters and setters
}

我配置了ehcache.xml文件:

  <cache name="com.domain.User"
           timeToIdleSeconds="1800"
           timeToLiveSeconds="3600">
    </cache>

开发 yml 文件

spring:
    devtools:
        restart:
            enabled: true
        livereload:
            enabled: false # we use gulp + BrowserSync for livereload
    datasource:
        url: jdbc:postgresql://localhost:xxx/cccccccc
        name: ccc
        username: cc
        password: cc
    jpa:
        database-platform: com.util.PostgreSQL82Dialect
        database: POSTGRESQL
        show_sql: true
        properties:
            hibernate.cache.use_second_level_cache: true
            hibernate.cache.use_query_cache: true
            hibernate.generate_statistics: true
            hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
    jhipster:
        cache: # Hibernate 2nd level cache, used by CacheConfiguration
            timeToLiveSeconds: 180
            ehcache:
                maxBytesLocalHeap: 16M

当我登录时,我的应用程序用户是从数据库中获取的。我注销并登录,用户总是从数据库中获取。 是否还有其他配置要添加? 谢谢

【问题讨论】:

    标签: caching spring-data-jpa ehcache jhipster


    【解决方案1】:

    如果要缓存查询结果。您需要在 Spring 中使用Cache Abstraction

    在您的实体存储库中,您需要添加类似的内容(代码来自上面的链接):

    @Cacheable("books")
    public Book findBook(ISBN isbn) {...} 
    

    注解@Cacheable 触发缓存填充。 @Cache 正在为实体添加缓存策略。

    【讨论】:

      猜你喜欢
      • 2016-08-01
      • 2021-05-09
      • 2011-09-04
      • 2023-03-15
      • 2016-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多