Chanakya
Chanakya

Reputation: 178

Is there a way to be notified when an entity in memcache is about to be dropped?

Is there a way to know when an entity stored in memcache is about to be dropped? For the purposes of persisting it to a more permanent datastore.

Upvotes: 0

Views: 53

Answers (2)

Patrice
Patrice

Reputation: 4692

As jdavidbakr pointed out, no way of being notified.

the best practice for memcache is using ndb if you're in python (as ndb already checks memcache before pushing to the datastore, so it'll hit memcache if memcache has the requested data).

if you're in a language that doesn't have ndb, I would suggest using taskqueues to insert data to the datastore (ie: "push entity to memcache and create a taskqueue to push to datastore"). For retrieve, you first look in memcache and then turn to the datastore if the entity isn't in memcache. In the event you had to visit datastore to get the data, push it back to memcache.

Upvotes: 1

jdavidbakr
jdavidbakr

Reputation: 195

I'd be very surprised if there is, memcache is designed to be a temporary data store that caches data from another source. Normally the way memcache would be used is when you need to access the data, memcache is checked first and then if not found the persistent store is checked. On an update you would either store the updated value in memcache in addition to the persistent store, or delete the memcache value and only store it in the permanent data store, then you would have it get pulled from the permanent store on the next data retrieval call. With this paradigm, you should always expect that memcache may or may not contain your data.

Upvotes: 3

Related Questions