Spring数据:Hibernate查询缓存不适用于派生查询
我正在尝试为Spring数据中由方法名派生的查询设置Hibernate查询缓存,但是查询缓存从未被使用,或者甚至似乎没有处于活动状态 我正在使用Spring BootSpring数据:Hibernate查询缓存不适用于派生查询,hibernate,spring-boot,kotlin,spring-data-jpa,caffeine,Hibernate,Spring Boot,Kotlin,Spring Data Jpa,Caffeine,我正在尝试为Spring数据中由方法名派生的查询设置Hibernate查询缓存,但是查询缓存从未被使用,或者甚至似乎没有处于活动状态 我正在使用Spring Boot2.2.1、Kotlin1.3.50、以及带有JCache扩展的咖啡因作为我的底层Hibernate缓存 我的存储库如下所示: @Repository interface LibraryRepository : JpaRepository<Library, Long> { @QueryHints(QueryHint(
2.2.1
、Kotlin1.3.50
、以及带有JCache扩展的咖啡因作为我的底层Hibernate缓存
我的存储库如下所示:
@Repository
interface LibraryRepository : JpaRepository<Library, Long> {
@QueryHints(QueryHint(name = CACHEABLE, value = "true"))
override fun findAll(sort: Sort): List<Library>
}
摘自我的配置:
spring:
jpa.properties:
javax.persistence.sharedCache.mode: ENABLE_SELECTIVE
hibernate:
generate_statistics: true
session.events.log: true
hibernate:
cache:
use_second_level_cache: true
use_query_cache: true
region.factory_class: org.hibernate.cache.jcache.JCacheRegionFactory
javax.cache.provider: com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider
但是,在查询libraryRepository.findAll(Sort.by(“name”))
时,始终会查询数据库
日志中没有提到有关查询缓存的内容
第一次调用(应该放在缓存中):
第二次调用(应命中缓存):
我的
yaml
有一个问题,没有正确缩进(!)
我的
yaml
有一个问题,没有正确缩进(!)
我不能对春天和冬眠说话。我的第一步是在我认为应该命中的库中添加断点,并从那里开始工作。感谢您的输入。事实上,我今天早上解决了它,我的yaml中有一个缩进问题:(我不能对Spring和Hibernate说话。我的第一步是在库中添加断点,我认为它应该在那里运行。感谢您的输入。事实上,我今天早上解决了它,我的yaml中有一个缩进问题:(
spring:
jpa.properties:
javax.persistence.sharedCache.mode: ENABLE_SELECTIVE
hibernate:
generate_statistics: true
session.events.log: true
hibernate:
cache:
use_second_level_cache: true
use_query_cache: true
region.factory_class: org.hibernate.cache.jcache.JCacheRegionFactory
javax.cache.provider: com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider
2019-12-16 18:14:09.955 DEBUG 20400 --- [nio-8080-exec-1] org.hibernate.SQL :
select
library0_.id as id1_3_,
library0_.created_date as created_2_3_,
library0_.last_modified_date as last_mod3_3_,
library0_.name as name4_3_,
library0_.root as root5_3_
from
library library0_
order by
library0_.name asc
2019-12-16 18:14:09.956 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Caching data from load [region=`cache.library` (AccessType[read-write])] : key[org.gotson.komga.domain.model.Library#73] -> value[CacheEntry(org.gotson.komga.domain.model.Library)]
2019-12-16 18:14:09.957 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Checking writeability of read-write cache item [timestamp=`6457308078116864`, version=`null`] : txTimestamp=`6457308159795200`, newVersion=`null`
2019-12-16 18:14:09.957 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Cache put-from-load [region=`AccessType[read-write]` (cache.library), key=`org.gotson.komga.domain.model.Library#73`, value=`CacheEntry(org.gotson.komga.domain.model.Library)`] failed due to being non-writable
2019-12-16 18:14:09.957 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Caching data from load [region=`cache.library` (AccessType[read-write])] : key[org.gotson.komga.domain.model.Library#3] -> value[CacheEntry(org.gotson.komga.domain.model.Library)]
2019-12-16 18:14:09.957 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Checking writeability of read-write cache item [timestamp=`6457308078116864`, version=`null`] : txTimestamp=`6457308159795200`, newVersion=`null`
2019-12-16 18:14:09.957 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Cache put-from-load [region=`AccessType[read-write]` (cache.library), key=`org.gotson.komga.domain.model.Library#3`, value=`CacheEntry(org.gotson.komga.domain.model.Library)`] failed due to being non-writable
2019-12-16 18:14:09.957 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Caching data from load [region=`cache.library` (AccessType[read-write])] : key[org.gotson.komga.domain.model.Library#33] -> value[CacheEntry(org.gotson.komga.domain.model.Library)]
2019-12-16 18:14:09.957 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Checking writeability of read-write cache item [timestamp=`6457308078116864`, version=`null`] : txTimestamp=`6457308159795200`, newVersion=`null`
2019-12-16 18:14:09.958 DEBUG 20400 --- [nio-8080-exec-1] o.h.c.s.support.AbstractReadWriteAccess : Cache put-from-load [region=`AccessType[read-write]` (cache.library), key=`org.gotson.komga.domain.model.Library#33`, value=`CacheEntry(org.gotson.komga.domain.model.Library)`] failed due to being non-writable
2019-12-16 18:14:09.958 DEBUG 20400 --- [nio-8080-exec-1] o.h.stat.internal.StatisticsImpl : HHH000117: HQL: select generatedAlias0 from Library as generatedAlias0 order by generatedAlias0.name asc, time: 3ms, rows: 3
2019-12-16 18:14:09.989 DEBUG 20400 --- [nio-8080-exec-1] m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json', given [*/*] and supported [application/json]
2019-12-16 18:14:10.025 DEBUG 20400 --- [nio-8080-exec-1] m.m.a.RequestResponseBodyMethodProcessor : Writing [[LibraryDto(id=73, name=All, root=file:/C:/Users/groebroe101209/files/all/), LibraryDto(id=3, name=C (truncated)...]
2019-12-16 18:14:10.123 INFO 20400 --- [nio-8080-exec-1] i.StatisticalLoggingSessionEventListener : Session Metrics {
35800 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
279300 nanoseconds spent preparing 1 JDBC statements;
154000 nanoseconds spent executing 1 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
1256401 nanoseconds spent performing 3 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
3500 nanoseconds spent executing 1 partial-flushes (flushing a total of 0 entities and 0 collections)
}
2019-12-16 18:14:35.180 DEBUG 20400 --- [nio-8080-exec-3] org.hibernate.SQL :
select
library0_.id as id1_3_,
library0_.created_date as created_2_3_,
library0_.last_modified_date as last_mod3_3_,
library0_.name as name4_3_,
library0_.root as root5_3_
from
library library0_
order by
library0_.name asc
2019-12-16 18:14:35.181 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Caching data from load [region=`cache.library` (AccessType[read-write])] : key[org.gotson.komga.domain.model.Library#73] -> value[CacheEntry(org.gotson.komga.domain.model.Library)]
2019-12-16 18:14:35.181 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Checking writeability of read-write cache item [timestamp=`6457308078116864`, version=`null`] : txTimestamp=`6457308263133184`, newVersion=`null`
2019-12-16 18:14:35.181 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Cache put-from-load [region=`AccessType[read-write]` (cache.library), key=`org.gotson.komga.domain.model.Library#73`, value=`CacheEntry(org.gotson.komga.domain.model.Library)`] failed due to being non-writable
2019-12-16 18:14:35.181 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Caching data from load [region=`cache.library` (AccessType[read-write])] : key[org.gotson.komga.domain.model.Library#3] -> value[CacheEntry(org.gotson.komga.domain.model.Library)]
2019-12-16 18:14:35.181 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Checking writeability of read-write cache item [timestamp=`6457308078116864`, version=`null`] : txTimestamp=`6457308263133184`, newVersion=`null`
2019-12-16 18:14:35.181 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Cache put-from-load [region=`AccessType[read-write]` (cache.library), key=`org.gotson.komga.domain.model.Library#3`, value=`CacheEntry(org.gotson.komga.domain.model.Library)`] failed due to being non-writable
2019-12-16 18:14:35.182 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Caching data from load [region=`cache.library` (AccessType[read-write])] : key[org.gotson.komga.domain.model.Library#33] -> value[CacheEntry(org.gotson.komga.domain.model.Library)]
2019-12-16 18:14:35.182 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Checking writeability of read-write cache item [timestamp=`6457308078116864`, version=`null`] : txTimestamp=`6457308263133184`, newVersion=`null`
2019-12-16 18:14:35.182 DEBUG 20400 --- [nio-8080-exec-3] o.h.c.s.support.AbstractReadWriteAccess : Cache put-from-load [region=`AccessType[read-write]` (cache.library), key=`org.gotson.komga.domain.model.Library#33`, value=`CacheEntry(org.gotson.komga.domain.model.Library)`] failed due to being non-writable
2019-12-16 18:14:35.182 DEBUG 20400 --- [nio-8080-exec-3] o.h.stat.internal.StatisticsImpl : HHH000117: HQL: select generatedAlias0 from Library as generatedAlias0 order by generatedAlias0.name asc, time: 2ms, rows: 3
2019-12-16 18:14:35.183 DEBUG 20400 --- [nio-8080-exec-3] m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json', given [*/*] and supported [application/json]
2019-12-16 18:14:35.183 DEBUG 20400 --- [nio-8080-exec-3] m.m.a.RequestResponseBodyMethodProcessor : Writing [[LibraryDto(id=73, name=All, root=file:/C:/Users/groebroe101209/files/all/), LibraryDto(id=3, name=C (truncated)...]
2019-12-16 18:14:35.186 INFO 20400 --- [nio-8080-exec-3] i.StatisticalLoggingSessionEventListener : Session Metrics {
73400 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
41301 nanoseconds spent preparing 1 JDBC statements;
180701 nanoseconds spent executing 1 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
1124001 nanoseconds spent performing 3 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
4000 nanoseconds spent executing 1 partial-flushes (flushing a total of 0 entities and 0 collections)
}
spring:
jpa.properties:
javax:
persistence.sharedCache.mode: ENABLE_SELECTIVE
cache.provider: com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider
hibernate:
generate_statistics: true
session.events.log: false
cache:
use_second_level_cache: true
use_query_cache: true
region.factory_class: org.hibernate.cache.jcache.JCacheRegionFactory