NDB caching not working on Google App Engine
Asked Answered
F

1

7

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?

Fluorene answered 18/1, 2013 at 15:4 Comment(0)
I
14

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().

Insomnolence answered 18/1, 2013 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.