-1

In an effort to reduce the number of datastore PUTs I am consuming I wish to use the memcache much more frequently. The idea being to store entities in the memcache for n minutes before writing all entities to the datastore and clearing the cache.

I have two questions:

Is there a way to batch PUT every entity in the cache? I believe makePersistentAll() is not really batch saving but rather saving each individually is it not?

Secondly is there a "callback" function you can place on entities as you place them in the memcache? I.e. If I add an entity to the cache (with a 2 minute expiration delta) can I tell AppEngine to save the entity to the datastore when it is evicted?

Thanks!

Mylo
  • 87
  • 4
  • 13

2 Answers2

0

makePersistentAll does indeed do a batch PUT, which the log ought to tell you clear enough

DataNucleus
  • 15,199
  • 3
  • 30
  • 37
  • Thanks DataNucleus. One remaining question I have is, calling entrySet() on my cache to get every entity saved in the cache and passing that to makePersistentAll() is fine; however, the api docs state: "If the map is modified while an iteration over the set is in progress the results of the iteration are undefined". My cache is updated very frequently so the map will be modified. So how do you prevent this from happening and persist each entity in the cache to the datastore? Thanks – Mylo Oct 01 '11 at 16:16
0

There's no way to fetch the entire contents of memcache in App Engine. In any case, this is a bad idea - items can be evicted from memcache at any time, including between when you inserted them and when you tried to write the data to the datastore. Instead, use memcache as a read cache, and write data to the datastore immediately (using batch operations when possible).

Nick Johnson
  • 98,961
  • 16
  • 125
  • 196