Sometimes (when I perform stress test) the object stored in memcache is corrupted (it lacks a property and when I try to access it gives me "NullPointerException"). Could it be related to wrong synchronization between different memcache writes? In fact in different part of my code I just update the UserAccount stored in Memcache in this way:
cache.put(tempUser.getKey(), tempUser);
.. and I try to retrieve in this way:
if (cache.contains(key)) {
readObject = (T) cache.get(key);
return readObject;
}
Related to this retrieving I get NullPointerException, when I try (for exampple) to retrieve:
readObject.getMyProperty()
I tried to understand this feature (https://developers.google.com/appengine/docs/java/memcache/overview#Safely_Handling_Concurrent_Memcache_Updates), but it doens't seem very well documented. I also had a look to these answers on stackoverflow:
- GAE MemCache behaviour of put() + ADD_ONLY_IF_NOT_PRESENT
- Safely Handling Concurrent Memcache Updates in AppEngine
.. but it doesn't seem realated to my needs. At the end I just need to be sure a value is well stored in the cache, without the risk of race condition could affect its integrity.
================================================================================ UPDATE: I try to specify better the behaviour: I get "NullPointerException" in this row:
if(readObject!=null && readObject.getMyProperty.equals("test"))
so that it is not (only) totally null, but just a property. It seems really to be corrupted. Apart from that I know I have to improve the retrieve phase!
================================================================================
NEW UPDATE: I found the object in memcache with all the properties equals to null, apart from the key one