ssm simple-spring-memcached - cache write not working

754 views Asked by At

I am using the SSMCache#put API directly to get a cache and update on a key.

Intially I have read the value from cache using below spring-cache annotated method.

@Cacheable(value="CACHE_JOURNALS", key="#ID") 
    public JournalBean getJournalByID(int ID){...}
...
[INFO] (CXServiceImpl.java:sendTo:78) read: [1, xxx, yyy, 5348 ]

then update the 'bean.count' field and write back.

cache.put(key, bean);
...
[INFO] (SSMCache.java:put:152) Put '[1, xxx, yyy, 5349 ]' under key 1 to cache CACHE_JOURNALS

Later a Spring service tries to read the cache(CACHE_JOURNALS), but the value of 'bean.count' is not updated in the cache and it is the old value (5348).

I hope I'm calling the right API to update a cache element. Any pointers?

1

There are 1 answers

1
ragnor On

Could you show how you've configured CACHE_JOURNALS?

You've enabled logging on SSM to see put command when invoking cache.put. Can you do the same for @Cacheable? Let's see under what key this object is stored in cache.

If you want to update element in cache you don't have to use SSM classes. You can use Spring annotation @CachePut.