Questions tagged [spring-cache]

Spring cache provides a Cache and CacheManager abstraction with several implementations including support for ehcache and JSR-107 providers. It also applies caching to Java methods, reducing thus the number of executions based on the information available in the cache. Both declarative annotation-based caching and aspect-oriented caching are supported.

Filter by
Sorted by
Tagged with
0 votes
1 answer
31 views

Spring Conditional Caching with Local Variables?

I have a Cacheable method that returns an object containing data from multiple sources. In case of an error (ex: A source is unavailable), it will return with whatever partial data was retrieved. ...
Alex's user avatar
  • 1
0 votes
0 answers
22 views

Spring boot + redis - request takes around same amount of time after restart

I have implemented Redis in my spring boot app using the following CacheConfig public RedisCacheConfiguration cacheConfiguration() { return RedisCacheConfiguration.defaultCacheConfig() ...
arohiman's user avatar
-1 votes
1 answer
38 views

EHCache 3 not able to enable caching. Getting exception if I used configuration without xml

I am trying to implement EHCache 3 with spring boot 3 without xml configuration. I did below configuration for EHCache 3 @Bean public CacheManager getCacheManager() { CacheManager ...
Shiladittya Chakraborty's user avatar
0 votes
0 answers
15 views

Using @Resource or @Autowired to prevent @Cacheable method from being ignored when called from the same class

I fixed the caching problem using @Resource or @Autowired, but is this correct? What problems can it cause? @Component @RequiredArgsConstructor public class AuthClientService { @Resource or @...
zoroglur's user avatar
  • 416
3 votes
2 answers
147 views

Unable to get collection from Redis cache

We are using Redis cache for storing data in cache in our application. We are directly using @Cacheable to allow caching and using redis underneath to cache. Below is the config Redis Config - @...
Neil's user avatar
  • 464
0 votes
1 answer
176 views

Spring Boot 3: Unable to gracefully fail and recover on Redis connection issue

I have a spring boot API which is using Redis. I'm trying to cover cases whereby when Redis goes down for whatever reason I am able to handle it and more importantly recover and serve from cache again....
MetaCoder's user avatar
  • 368
0 votes
1 answer
40 views

Can I set a TTL for @Cacheable EhCache per entry?

I need to set TTL per cache entry. I use EhCache, Spring Cache. EhCache does not provide an API to supply a TTL for a put method. An alternative way would be to create multiple caches with different ...
isobretatel's user avatar
  • 3,832
0 votes
1 answer
38 views

How to call a method for "value" attribute of cacheable annotation in Java Spring

I have this abstract repository class: public abstract class FirestoreRepository<T> { protected Firestore db; protected FirestoreRepository(Firestore db) { this.db = db; } ...
quasimodo's user avatar
0 votes
0 answers
26 views

Issue with the logic determining cache hits and cache miss in CacheAspectSupport Spring

@Caching(cacheable = { @Cacheable(cacheManager = "localCacheManager"), @Cacheable(cacheManager = "redisCacheManager"), } ) I can implement a memory ...
gisulee's user avatar
  • 47
0 votes
1 answer
61 views

Spring caching works "live" but not in tests

I have a service at work using Spring framework (not Boot!) with a guava cache. I would like to use Spring's own facilities. I can get it to work running the actual app, but in tests the caching doesn'...
Erik Vesterlund's user avatar
0 votes
0 answers
31 views

Hazelcast spring-boot entity cache

We currently utilize Hazelcast in a non-clustered environment alongside Spring Cache Abstraction. However, we now intend to transition into a clustered environment and require our cache to be ...
user1470509's user avatar
0 votes
0 answers
79 views

Spring cache fails to deserialise empty array

I have following Redis cache setup private RedisCacheConfiguration redisCacheConfiguration() { return RedisCacheConfiguration.defaultCacheConfig() .disableCachingNullValues() ....
absence's user avatar
  • 328
0 votes
1 answer
50 views

Guava Cache Access From Different Classes

Is it possible to access the guava cache from any of the class within that project? Suppose if I create class cache bannelUrl within FetchBanner.java, can the values from bannelUrl from any other ...
Jithesh Nair's user avatar
0 votes
1 answer
91 views

Why @Cacheable return different result on subsequent calls

I am running Spring Boot version 2.6.14. Controller @PostMapping("/v1/books) public GenericResponse<Book> getBooks(BookRequest request) { return new GenericResponse<>( ...
Denis Kisina's user avatar
0 votes
0 answers
16 views

Using Spring Cache with HystrixCommand is not working

Using Spring Cache with HystrixCommand is not working as if the @Cacheable is not there. no logs about caching by debuging. the Method will always called. here is the code: @Override @Cacheable(value =...
progro's user avatar
  • 1
0 votes
1 answer
587 views

Spring cache using redis does not store data in the cache

I have a spring boot 2.4.1 application where I configured spring cache with redis. I have a service with the following method: @Cacheable(value = "myCache", key = "'fixed'") ...
Oscar B's user avatar
  • 21
1 vote
2 answers
646 views

CacheManger defined as bean and in application.yaml

In Spring Boot, I would like to use one cache manager defined as bean plus Redis cache defined in application.yaml. But after define cache manager like bean the other one in application.yaml is ...
Pavel Hora's user avatar
0 votes
2 answers
120 views

Unable to create requested service [org.hibernate.cache.spi.CacheImplementor] Hibernate Cache in Spring Boot

I am trying to hibernate cache in Spring dao layer. I get an error when I add the ehcache dependency. application.properties spring.jpa.properties.hibernate.cache.use_second_level_cache=true spring....
zoroglur's user avatar
  • 416
0 votes
1 answer
35 views

Unable to store and retrieve Spring HATEOAS EntityModel in Redis

I have a use case where we are trying to store and retrieve content from Redis cache. We are using spring-starter-cache for making use of the underlying redis cache storage. @Bean public ...
Abhilash's user avatar
  • 803
1 vote
3 answers
492 views

How to clear Spring Cache without Scheduled annotation

I am caching with Spring cache. How to clear cache without Scheduled Job?
zoroglur's user avatar
  • 416
0 votes
1 answer
492 views

How to Cache Pageable in Spring Boot?

I am trying to cache Pageable in Spring Boot. How do I handle caching for each page passed in pageable object? @Service public class MarketServiceImpl implements MarketService { @Autowired MarketDao ...
Pratyush Pranjal's user avatar
0 votes
0 answers
54 views

Why Spring DefaultRedisCacheWriter doesn't support secondary index?

Background I'm using a single redis cluster for caching and storing data. As the storing data grew, cache evicting speed was getting slower. After debugging, I figure out that the ...
Patrick Shim's user avatar
1 vote
1 answer
412 views

Spring caching + how to put result of @Cachable into multiple caches

I have a service that resolve customer identifiers in some domain. I have a simple pojo model of a customer identifiers: @Data public class Identifiers { private String accountNumber; private ...
snej0keee's user avatar
1 vote
2 answers
874 views

Bean request scope: No thread-bound request found on Spring Boot start

I am trying to instantiate a simple cache that is request-scoped. @Configuration @EnableCaching public class CacheConfiguration { @Bean @Scope(value = WebApplicationContext.SCOPE_REQUEST, ...
mitchkman's user avatar
  • 6,211
0 votes
1 answer
320 views

Is there a way to apply Spring caching functionality for saveAll Or updateAll with Cacheable function, respectively?

@CachePut(cacheNames = "projectTeams", key = "#projectTeam.id") public List<ProjectTeam> updateAll(List<ProjectTeam> projectTeam) { return projectTeamRepository.save(...
Ashish Rana's user avatar
1 vote
2 answers
2k views

Modify Spring's RedisCacheConfiguration

I'm setting the configuration of a Spring Data Redis Cache on application.properties using the spring.cache.redis.* keys. However, not everything is possible to be configured on application.properties ...
Fábio's user avatar
  • 3,299
0 votes
1 answer
106 views

How to Loop through InfiniSpan Cache entries

i am using infinispan cache and have to loop through all the entries in a cache and find out cache keys and values. i've found that it can be done through entrySet using below approach cache.entrySet()...
Faheem Sultan's user avatar
0 votes
0 answers
114 views

Ehcache 2 is not expiring after ttl time end

I have set expiry time as 5 minutes, but after 5 minutes , the value is picked form the cache it self not calling the actual method. The cache is not getting expired after ttl completion. CacheConfig....
shruti garg's user avatar
0 votes
0 answers
460 views

Leverage Spring boot Redis Auto configure logic for RedisConnectionFactory

Spring boot auto configures RedisConnectionFactory if spring-data-redis exists on classpath and RedisConnectionFactory is initialized in LettuceConnectionConfiguration if Lettuce-core available on ...
Srinivas karre's user avatar
1 vote
1 answer
930 views

Synchronize multiple instances of Spring Cache with a Redis lock

I'm building a Spring Boot application that uses Spring Cache with a Redis backing store and needs to synchronize the updates made to the cache. The caching is not made on the fly, but by an scheduled ...
Fábio's user avatar
  • 3,299
0 votes
1 answer
525 views

Spring @Cacheable - is it possible to make reads from the cache without making writes to it?

I have two micro services and I need one of them to read the cache, but never update it. I tried to put @Cacheable(cacheNames = "test-stack", key=..., unless="true") and @...
Don_Quijote's user avatar
0 votes
1 answer
487 views

More than 1 caching storage in Spring Boot app

I am facing a strange issue - I have hazelcast and redis in my project. Suddenly all @Cacheable annotations are putting entries only to hazelcast cache, even if the particular cache name is configured ...
Mejmo's user avatar
  • 2,383
4 votes
1 answer
97 views

How to use cache with Google Sheets in Spring Boot?

I am just starting to learn Spring Boot and am trying to use cache with the Google Sheets API to study Springboot. To use cache with Google Sheets in Spring Boot, I added the spring-boot-starter-cache ...
Dennis Wong's user avatar
1 vote
1 answer
373 views

How to avoid changing object in cache before saving Spring Cache

I want to show right away with an example. There is such a repository: @Repository public interface UserRepository extends JpaRepository<User, Integer> { String USER_CACHE = "users"; ...
SnejOK's user avatar
  • 75
0 votes
1 answer
1k views

Instantiate a CacheManager bean in Spring Boot application

I am using @Service public class Service{ @Autowired private CacheManager cacheManager; } I included org.ehcache:ehcache and spring-boot-starter-cache library in the build.gradle file. on ...
juan's user avatar
  • 47
0 votes
0 answers
89 views

Caching a function with refresh rate

I have the following scenario. Below is a minimalist version of what I am trying to do in a simple spring boot REST API Controller and Service. func() { String lv=vService.getlv("1.2.1"); ...
juan's user avatar
  • 47
0 votes
0 answers
55 views

Spring Cloud config with JDBC Backend Failure in Spring boot

I have a client-server based microservice architecture. i.e, a server-config(Spring cloud config) service that has all the configurations and properties that are fetched using jdbc Backend-(PostgreSQL ...
user20847411's user avatar
0 votes
0 answers
389 views

How to save raw java Map to Redis as Redis Hash by using Spring @Cacheable

How to save raw java Map to Redis as Redis Hash by using Spring @Cacheable. @Cacheable(cacheNames = "test:role", key = "#roleId") public Map<String, String> getRoleName(...
Neal.Shan's user avatar
  • 128
0 votes
1 answer
2k views

Is an explicit CacheManager bean definition mandatory when using Spring Boot + Spring Cache?

From documentation Spring Boot uses ConcurrentMapCacheManager as CacheManager implementation by default if we don't define own CacheManager bean definition. But I keep getting 'No qualifying bean of ...
SetNug's user avatar
  • 341
0 votes
0 answers
36 views

Evict an entry based on fewer/different keys than that used for caching in Spring

Does Sprin-Cache support evicting selected entries based on fewer keys or different keys than those used while creating the entry? User may be fetched by username and withTransactions=true User may ...
Kumar Ashutosh's user avatar
0 votes
0 answers
22 views

Cache evict on every DML operation

I have couple of findBy... methods in my spring application for instance findById(int id) findByName(String name) findByCity(String city) etc... For every method I have a cache key like 1. person.id....
anonymous's user avatar
0 votes
0 answers
168 views

cache evict with random method parameters, how can i remove my cache with parametres containing

Hello guys i'm having a big big dilema, i have a methode cacheable with a hashSet, i want to delete this cache for all the cacheable data that contains a specific value in the HashSet. is it possible ...
Abdel's user avatar
  • 49
0 votes
1 answer
3k views

No qualifying bean of type 'feign.Client' available being thrown in the background

There is an exception being thrown in the background of my application. The error is not logged but it's caught by a third-party tool called Dynatrace, due to this tool we were able to see the ...
EduwHS's user avatar
  • 13
0 votes
0 answers
122 views

Spring Cache - partial cache elements in list inside of DTO

So from my understanding in bellow code, when string ID is already in cache as key, DTO value gets returned from cache, instead of calling externalService method: @Cachable("elements") ...
λjk.jk's user avatar
  • 127
0 votes
1 answer
287 views

Why does Hazelcast not show entry in the Map when added via CachePut/Cacheable

I have a use case where by the @CachePut annotation adds an entry to the cache, and I have to retrieve it manually (via code). I can see that the total backup count gives me 1 as the number of entries,...
alpheus's user avatar
  • 240
0 votes
0 answers
167 views

Ehcache 3 CacheManager NullPointerException

I have the below config @Configuration @EnableCaching(proxyTargetClass = true) public class CachingConfig { @Bean @ConditionalOnMissingBean public javax.cache.CacheManager cacheManager() {...
Aymen Kanzari's user avatar
0 votes
0 answers
339 views

Cannot find cache for Builder when using same Cache Provider in two different dependencies

In my app I have two dependencies, A and B. Dependency A is a library of mine, but dependency B is not. Both dependencies make use of Caffeine to cache the results in memory. This is the configuration ...
Marcos's user avatar
  • 304
1 vote
1 answer
699 views

Can we first validate the existing data in the cache then go for the missing keys in Spring Boot Cache?

I want fetch the data from the table . table Name : Student Student { int id; String Name; }; I have query : select Name from Student where id in (:ids); Need : When I call the repository ...
Akash Yadagouda's user avatar
0 votes
0 answers
26 views

Use of Spring Cache on web methods

I am supporting a website which was built with Spring MVC (version 5.2.8) and runs on Tomcat (version 8.5.54). I tested Spring Cache on service methods and database methods, and it worked. However, I ...
curious1's user avatar
  • 14.2k
0 votes
1 answer
34 views

How can I add param to JPA query which will be ignored by JPA?

There is an idea of optional caching of results of query: public interface SomethingRepository extends PagingAndSortingRepository<Something, String> @Cacheable(value = "listOfSomething&...
Starkom's user avatar
  • 31

1
2 3 4 5
14