spring-cache

Spring cache using @Cacheable during @PostConstruct does not work

落花浮王杯 提交于 2019-11-29 14:55:21
问题 related to the commit in spring framework https://github.com/spring-projects/spring-framework/commit/5aefcc802ef05abc51bbfbeb4a78b3032ff9eee3 the initialisation is set to a later stage from afterPropertiesSet() to afterSingletonsInstantiated() In short : This prevents the caching to work when using it in a @PostConstruct use case. Longer version : This prevents the use case where you would create serviceB with @Cacheable on a methodB create serviceA with @PostConstruct calling serviceB

Issues with testing Spring's declarative caching support on a Spring data repository

☆樱花仙子☆ 提交于 2019-11-29 11:28:24
I am trying to test Spring caching support (as described here ) for a Spring Data JPA repository (that extends JpaRepository ) and I am actually having issues with my configuration. Here is my repository method: @Cacheable(value = CacheConfiguration.DATABASE_CACHE_NAME) Member findByEmail(String email); Here is my CacheConfiguration: @Configuration @EnableCaching public class CacheConfiguration implements CachingConfigurer { public static final String DATABASE_CACHE_NAME = "cache.database"; @Bean @Override public CompositeCacheManager cacheManager() { CompositeCacheManager cacheManager = new

How do I use the key, in a condition in Cacheable annotation

懵懂的女人 提交于 2019-11-29 04:39:21
I'm caching the results of a function using the @cacheable annotation. I have 3 different caches and the key for each one is the user id of the currently logged in user concatenated with an argument in the method . On a certain event I want to evict all the cache entries which have the key that starts with that particular user id. For example : @Cacheable(value = "testCache1", key = "'abcdef'") I want the cache evict annotation to be something like : @CacheEvict(value = "getSimilarVendors", condition = "key.startsWith('abc')") But when I try to implement this it gives me an error : Property or

Spring Boot - How to disable @Cachable during development?

二次信任 提交于 2019-11-28 23:19:47
I'm looking for 2 things: How to disable all caching during development with Spring boot "dev" profile. There doesn't seam to be a general setting to turn it all off in application.properties. What's the easiest way? How to disable caching for a specific method? I tried to use SpEl like this: @Cacheable(value = "complex-calc", condition = "#{${spring.profiles.active} != 'dev'}") public String someBigCalculation(String input){ ... } But I can get it to work. There are a couple of questions on SO related to this, but they refer to XML config or other things, but I'm using Spring Boot 1.3.3 and

How to have multiple cache manager configuration in spring cache java

ⅰ亾dé卋堺 提交于 2019-11-28 05:25:19
I want to have multiple spring cache managers configured in my web-application and I would be able to use different cache manager at various places in my project. Is there any way to do this. Stephane Nicoll There are several ways you can do this and the right answer depends on your usage of the cache. You have a "main" cache manager If you use CacheManager A for 90% of your use case and B for 10% I'd advise to create a default CacheManager for A (you'll need to specify it via a CacheConfigurerSupport extension), something like: @Configuration @EnableCaching public class CacheConfig extends

Issues with testing Spring's declarative caching support on a Spring data repository

眉间皱痕 提交于 2019-11-28 04:16:07
问题 I am trying to test Spring caching support (as described here) for a Spring Data JPA repository (that extends JpaRepository ) and I am actually having issues with my configuration. Here is my repository method: @Cacheable(value = CacheConfiguration.DATABASE_CACHE_NAME) Member findByEmail(String email); Here is my CacheConfiguration: @Configuration @EnableCaching public class CacheConfiguration implements CachingConfigurer { public static final String DATABASE_CACHE_NAME = "cache.database";

spring @Cacheable with Ehcache, spel find null for valid object

老子叫甜甜 提交于 2019-11-28 02:16:13
I have a similar problem which but sometimes it works. The error described only happens once in a while. I am using spring 3.2.5 and ehcache 2.6.5. Exception trace: org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'applicationID' cannot be found on null at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213) at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85) at org.springframework.expression.spel.ast

How do I use the key, in a condition in Cacheable annotation

别说谁变了你拦得住时间么 提交于 2019-11-27 18:33:02
问题 I'm caching the results of a function using the @cacheable annotation. I have 3 different caches and the key for each one is the user id of the currently logged in user concatenated with an argument in the method . On a certain event I want to evict all the cache entries which have the key that starts with that particular user id. For example : @Cacheable(value = "testCache1", key = "'abcdef'") I want the cache evict annotation to be something like : @CacheEvict(value = "getSimilarVendors",

What strategies exist for using Spring Cache on methods that take an array or collection parameter?

删除回忆录丶 提交于 2019-11-27 15:43:11
I want to use Spring's Cache abstraction to annotate methods as @Cacheable. However, some methods are designed to take an array or collection of parameters and return a collection. For example, consider this method to find entites: public Collection<Entity> getEntities(Collection<Long> ids) Semantically, I need to cache Entity objects individually (keyed by id), not based on the collection of IDs as a whole. Similar to what this question is asking about. Simple Spring Memcached supports what I want, via its ReadThroughMultiCache , but I want to use Spring's abstraction in order to support easy

How to disable Redis Caching at run time if redis connection failed

落花浮王杯 提交于 2019-11-27 14:51:06
问题 We have rest api application. We use redis for API response caching and internal method caching. If redis connection then it is making our API down. We want to bypass the redis caching if that redis connection fails or any exception instead of making our API down. There is a interface CacheErrorHandler but it handles the redis get set operation failures not redis connection problems. We are using Spring 4.1.2. 回答1: Let's boil this down a bit. Your application uses caching (implemented with