Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NDB caching not working on Google App Engine

I switched to NDB for a new app, which as I understand includes memcache support 'for free'.

So I put an entity in the datastore:

class MyStorage(ndb.Model):
    pickled_data = ndb.BlobProperty()

obj = MyStorage(parent=ndb.Key('top_level_key', 'second_level_key'), pickled_data = pickle.dumps(my_attr))
obj.put()

In other requests I then retrieve using

obj = pickle.loads(MyStorage.query(ancestor = ndb.Key('top_level_key', 'second_level_key')).get().pickled_data)

But the delay in testing it when deployed on app engine tells me there's no caching going on (obviously none expected on the first call, but subsequent calls should show a speed up).

I check Memcache Viewer and sure enough, zeroes under every metric. So I'm obviously not getting something regarding free NDB caching. Can someone point out what it is?

like image 977
user1561108 Avatar asked Jan 18 '13 15:01

user1561108


1 Answers

NDB will only read from cache when you use .get_by_id() (or .get() on a Key). It won't be used when you use .query().

like image 191
Greg Avatar answered Oct 04 '22 20:10

Greg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!