I am writing multiple entites to the datastore using a transaction. I want to keep these entities in MemCache, also. How do I ensure that the copy of the entity in MemCache actually equals the copy in Datastore?
E.g. I can do:
tx.begin()
datastore.put(entity)
if (memcache.putIfUntoched(key, entity))
tx.commit()
But then if the transaction fails the entity will possibly end up in the MemCache but not in the Datastore. On the other hand, if I do:
tx.begin()
datastore.put(entity)
tx.commit()
memcache.putIfUntoched(key, entity))
then the Datastore transaction might succeed but the MemCache update could fail. How can I ensure consistency?
From my experience, it may not be that helpful if you write to the DB and the cache at the same time. In general, mixing DB transactions with other stuffs (e.g. file system) is difficult to do it right.
I suggest you change your program logic, so that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With