views:

85

answers:

1

Hi, I'm looking for a way to keep the equivalent of persistent global variables in app engine (python). What I'm doing is creating a global kind that I initialize once (i.e. when I reset all my database objects when I'm testing). I have things in there like global counters, or the next id to assign certain kinds I create.

Is this a decent way to do this sort of thing or is there generally another approach that is used?

+4  A: 

The datastore is the only place you can have guaranteed-persistent data that are also modifiable. So you can have a single large object, or several smaller ones (with a name attribute and others), depending on your desired access patterns -- but live in the datastore it must. You can use memcache for faster cache that usually persists across queries, but any memcache entry could go away any time, so you'll always need it to be backed by the datastore (in particular, any change must go to the datastore, not just to memcache).

Alex Martelli
ok, great responses. It sounds like the approach of creating some Kind that I create one instance of and access when needed was the way to go (unless I understand the responses incorrectly). Thanks!
Joey
@Joey, unless you need to be more selective in your access, the one instance approach is viable (be careful if two different queries can be modifying the instance at the same time, of course: any modification requires a transaction which re-reads, changes, and stores, else the changes may trample upon each other).
Alex Martelli