简体   繁体   English

谷歌应用程序引擎持久性全局变量

[英]google app engine persistent globals

I'm looking for a way to keep the equivalent of persistent global variables in app engine (python). 我正在寻找一种方法来在应用程序引擎(python)中保持等同于持久性全局变量。 What I'm doing is creating a global kind that I initialize once (ie 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. 我那里有诸如全局计数器之类的东西,或者是分配我创建的某些种类的下一个ID。

Is this a decent way to do this sort of thing or is there generally another approach that is used? 这是做这种事情的一种体面的方法吗?还是通常使用另一种方法?

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. 因此,根据所需的访问模式,您可以有一个大对象,也可以有几个小对象(具有name属性和其他属性),但是必须存在于数据存储中。 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). 您可以将memcache用于通常在查询中持续存在的更快的缓存,但是任何memcache条目都可能随时消失,因此,您始终需要它由数据存储支持(特别是,任何更改都必须移至数据存储,而不仅仅是到内存缓存)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM