0
votes

I am attempting to delete an object from the GAE datastore and then cache the remaining datastore objects with memcache. The object is being successfully deleted, but for some reason the python log and the memcache are not recognizing that one was deleted. The Datastore Viewer shows that the object is deleted, but the log says the the length of the items is not changing... also the memcache is just caching all of the items, as if no deletion is happening. Any advice you can give is much appreciated.

Python code:

 yesterday = datetime.now()-timedelta(days=1)  # one day ago                
 sessions = db.GqlQuery("SELECT * FROM MentorAvailSessions WHERE created > :1", yesterday).fetch(1000)   #pulling list of all objects
 logging.info('************** len before deleting a session: %s*********' % len(sessions)) # shows a length of 3    

 for session in sessions:
     if (session.session_id == end_session_id) and (session.user == user_info.username):
         session.delete();

 remaining_sessions = db.GqlQuery("SELECT * FROM MentorAvailSessions WHERE created > :1", yesterday).fetch(1000)  #pulling list of just the remaining objects after deleting one
 logging.info('** len of remaining sessions: %s' % len(remaining_sessions))  # still shows a length of 3 after session.delete                       

 memcache.set('mentor_avail_sessions_cache', remaining_sessions, time=50000)      # is caching all three items instead of just the remaining 2
1

1 Answers

1
votes

This is due to eventual consistency. Queries without an ancestor are not guaranteed to be strongly consistent (the dev server exaggerates this effect to make you aware of it, in production you rarely see inconsistencies).

You should ensure that your query uses an ancestor so that it supplies to an entity group. Alternatively, you could decrement the memcache counter explicitly, rather than refreshing it from a query.