我是GAE的memcache新手,在这方面我需要帮助。基本上,我有一个超过了数据存储读取操作限制的数据存储,因为我没有使用memcache。我的数据存储有最少的写操作,但有很多读操作,每次写操作时,它都应该可用于读操作。因为,该网站上,我需要一个快速的解决方案,所以我需要在这方面的设计帮助。所以问题是,只要在数据存储中有写操作,新的条目就应该被memcached。我还想知道如何将数据存储复制到memcache中。同时,我正在做这件事,但由于网站已经上线,所以我在没有任何代码的情况下在这里询问。
谢谢
更新:
Java代码如下所示:
MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
if(memcache.contains("LocationInfo"))
{
JSONArray js = new JSONArray((String)memcache.get("LocationInfo"));
result = new ArrayList<LocationInfo>();
for(int i = 0; i < js.length(); i++)
{
JSONObject jso = (JSONObject)js.get(i);
LocationInfo loc = new LocationInfo(jso);
result.add(loc);
}
}
else
{
q1= pm.newQuery(LocationInfo.class);
q1.setFilter(filter);
result = (List<LocationInfo>)q1.execute();
JSONArray js = new JSONArray();
for(LocationInfo loc : result)
{
js.put(loc.toJSON());
}
memcache.put("LocationInfo", js.toString());
}发布于 2012-06-26 13:40:38
from google.appengine.ext import db
from google.appengine.api import memcache
def top_arts(update = False):
key = 'top'
#Getting arts from memcache
arts = memcache.get(key)
#Check if key is defined in memcache
#or an update has been invoked
if update or not arts:
#Querying the Google Data store using GQL
arts = db.GqlQuery('SELECT * from Art ORDER BY created DESC LIMIT 10')
memcache.set(key, arts)
return arts您可以使用相同的函数从memcache读取数据,然后将数据写入memcache
例如:
用于从memcache读取:
arts = top_arts()写入数据库时:-
#write your entry in database
<some database code>
#update memcache with this new entry
top_arts(update=True)https://stackoverflow.com/questions/11201004
复制相似问题