0

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?

ragnor
  • 2,498
  • 1
  • 22
  • 25
JayabalanAaron
  • 360
  • 3
  • 13

1 Answers1

0

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.

ragnor
  • 2,498
  • 1
  • 22
  • 25
  • @Cacheble annotated method 'getJournalByID' was in the same bean and was being called for reading the element from cache. Spring doesnot intercept calls to methods in same bean. Discussed and solved [here](https://groups.google.com/forum/#!topic/simple-spring-memecached/hLq7aSrrjtA). – JayabalanAaron Aug 07 '14 at 16:04