spring-cache

Register Caffeine Cache in Spring Actuator (CacheManager)

一曲冷凌霜 提交于 2021-02-18 19:00:23
问题 We're using Spring Boot 2 and Spring Actuator. When creating a cache like the following: @Bean public CaffeineCache someCache() { return new CaffeineCache("my-cache", Caffeine.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.SECONDS) .build()); } it is registered into Spring Actuator and can be accessed and handle via endpoints: ❯ http GET localhost:8080/actuator/caches { "cacheManagers": { "cacheManager": { "caches": { "my-cache": { "target": "com.github.benmanes.caffeine.cache

Register Caffeine Cache in Spring Actuator (CacheManager)

一个人想着一个人 提交于 2021-02-18 19:00:07
问题 We're using Spring Boot 2 and Spring Actuator. When creating a cache like the following: @Bean public CaffeineCache someCache() { return new CaffeineCache("my-cache", Caffeine.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.SECONDS) .build()); } it is registered into Spring Actuator and can be accessed and handle via endpoints: ❯ http GET localhost:8080/actuator/caches { "cacheManagers": { "cacheManager": { "caches": { "my-cache": { "target": "com.github.benmanes.caffeine.cache

Register Caffeine Cache in Spring Actuator (CacheManager)

一个人想着一个人 提交于 2021-02-18 18:59:54
问题 We're using Spring Boot 2 and Spring Actuator. When creating a cache like the following: @Bean public CaffeineCache someCache() { return new CaffeineCache("my-cache", Caffeine.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.SECONDS) .build()); } it is registered into Spring Actuator and can be accessed and handle via endpoints: ❯ http GET localhost:8080/actuator/caches { "cacheManagers": { "cacheManager": { "caches": { "my-cache": { "target": "com.github.benmanes.caffeine.cache

Spring's AspectJ-mode caching versus AspectJ-mode transactions

空扰寡人 提交于 2021-02-18 11:44:07
问题 My question relates to Spring's AspectJ mode and especially how to enable it for: Transaction management Caching 1) I noticed that in order to enable the AspectJ mode for transaction management, I only had to do the following: @Configuration @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) 2) Whereas in order to use AspectJ mode for caching it seems one has to: -Put the following jar into Tomcat's lib directory: org.springframework:spring-instrument-tomcat -Add the following line in

Caffeine Cache in Spring Boot Cache : Get all cached keys

与世无争的帅哥 提交于 2021-02-10 20:42:30
问题 I'm using Caffeine Cache library for Spring Cache. Is there a way to get all the cached keys? My current application works on a near-realtime data, with the flow as : In the Cache Updater Thread (which runs at a fixed interval, irrespective of the user request), I need to get all the keys currently in the Cache, fetch their latest data from Db & then use @CachePut to update the cache. 回答1: Yo can inject CacheManager and obtain native cache from it. @AllArgsConstructor class Test { private

Caffeine Cache in Spring Boot Cache : Get all cached keys

為{幸葍}努か 提交于 2021-02-10 20:41:48
问题 I'm using Caffeine Cache library for Spring Cache. Is there a way to get all the cached keys? My current application works on a near-realtime data, with the flow as : In the Cache Updater Thread (which runs at a fixed interval, irrespective of the user request), I need to get all the keys currently in the Cache, fetch their latest data from Db & then use @CachePut to update the cache. 回答1: Yo can inject CacheManager and obtain native cache from it. @AllArgsConstructor class Test { private

Spring force @Cacheable to use putifAbsent instead of put

江枫思渺然 提交于 2021-02-08 10:01:44
问题 I've Spring cache implemented as below @Component public class KPCacheExample { private static final Logger LOG = LoggerFactory.getLogger(KPCacheExample.class); @CachePut(value="kpCache") public String saveCache(String userName, String password){ LOG.info("Called saveCache"); return userName; } @Cacheable(value="kpCache") public String getCache(String userName, String password){ LOG.info("Called getCache"); return "kp"; } } And Java Config file @Configuration @ComponentScan(basePackages={"com

How to use @CachePut and @CacheEvict on the same method in a Spring Boot application?

醉酒当歌 提交于 2021-02-08 08:56:50
问题 I'm working on a Spring Boot application where I have a scenario to put @CachePut and @CacheEvict on the same method. I tried the scenario with this code given below : @CachePut(value="myValue",key="#entity.getId(),#entity.getOrgId()", cacheManager="no-expire-caching") @CacheEvict(value="myValue", key="#entity.getId(),#entity.getOrgId()", cacheManager="no-expire-caching", condition="#entity.isDeleted() == true") public MyEntity save(boolean flag, MyEntity entity){ if (flag==true){ entity

How to use @CachePut and @CacheEvict on the same method in a Spring Boot application?

情到浓时终转凉″ 提交于 2021-02-08 08:56:30
问题 I'm working on a Spring Boot application where I have a scenario to put @CachePut and @CacheEvict on the same method. I tried the scenario with this code given below : @CachePut(value="myValue",key="#entity.getId(),#entity.getOrgId()", cacheManager="no-expire-caching") @CacheEvict(value="myValue", key="#entity.getId(),#entity.getOrgId()", cacheManager="no-expire-caching", condition="#entity.isDeleted() == true") public MyEntity save(boolean flag, MyEntity entity){ if (flag==true){ entity

cannot access net.sf.ehcache.CacheManager, class file for net.sf.ehcache.CacheManager not found

﹥>﹥吖頭↗ 提交于 2021-02-07 14:31:14
问题 I have been implementing some caching in my project using EhCache . I have added following dependencies to my pom.xml <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.8.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring