This is a very general question regarding GAE / Java Memcache :
I have an object called Network which is stored in the Memcache , and I have another object called User which has a reference to Network .
Network network=Memcache.get(networkKey);
user._network=network; //user references an object that came from Memcache...
now I have a bunch of code that changes user._network(without touching Memcache) :
user._network= // do some changes to the objects , without touching Memcache
Ok so here’s the question ,
Looking at the code as it is , did the last line update the network object in the memcache? I have servlets that need to access the updated network object , the question is if I’m wrong by thinking at Memcache objects as regular objects .
Perhaps the right way is this ?
Network network=Memcache.get(networkKey);
network.doUpdate();
Memcache.put(key,network);
The latter code example you provided is the correct way to update the network object in memcache, but I it will work differently than the way you expect.
Your user object refers to an instance of the network object that has been retrieved from memcache. Each time you retrieve the object from memcache you will get a different instance. And, because the instances are logically distinct from the original within the cache, as soon as the cached value is updated, those instances will become out of sync with the cached version.
For example:
You’ll need additional logic in your code if you want your User objects to always refer to the version of network that is in memcache.