robelgado
robelgado

Reputation: 133

Using @Cacheable Spring annotation and manually add to Infinispan Cache

I am trying to load my cache off of a cold start, prior to application startup. This would be done so values are available as soon as a user accesses a server, rather than having to hit my database.

@Cacheable functionality from Spring all works great, the problem is how I manually store objects in the Cache so that they can be read when the function is executed.

Spring is storing these objects in bytes, somehow -- and I need to mimic this while I manually load the cache. I'm just trying to figure out how they process the return objects, in the function, to store into the cache in a key,val pair.

Upvotes: 2

Views: 8605

Answers (2)

robelgado
robelgado

Reputation: 133

I was able to solve this problem by storing values as a string key and object value -- which works wonderfully with Spring @Cacheable annotations. Objects are casted into the return types by Spring if they are found within the cache.

Upvotes: 3

Michael
Michael

Reputation: 1184

You can programmatically access any cache by using Spring's CacheManager.

See https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/CacheManager.html

var cache = cacheManager.getCache("foo");

cache.put(key, value);

Upvotes: 9

Related Questions