2

저는 GAE의 memcache를 처음 사용했으며 이에 대한 도움이 필요합니다. 기본적으로 Memcache를 사용하지 않았기 때문에 Datastore 읽기 작업 제한을 초과 한 데이터 저장소가 있습니다. 데이터 저장소에는 최소한의 쓰기가 있지만 많은 읽기와 쓰기가있을 때마다 읽을 수 있어야합니다. 이후, 사이트가 작동하고 있으므로이 디자인 도움말이 필요하므로 빠른 해결책이 필요합니다. 그래서, 데이터 저장소에 쓰기가있을 때마다 새로운 항목이 memcached가되어야합니다. 데이터 저장소를 memcache에 복제하는 방법을 알고 싶습니다. 병렬로, 나는 그것에 노력하고있다. 그러나 사이트가 위로 있기 때문에 나는 어떤 코드도없이 그것을 여기에서 요구하고있다.Google App Engine memcached 디자인

감사

UPDATE :

자바 코드는 다음과 같습니다 :

 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()); 
     } 

답변

1
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) 
+0

기본적으로 내가 자바를 사용하고 있지만 크게 다르지 않을 것입니다. 나는 그것을 시도 할 것이다. – piyush

+0

자바에서는 간단하지가 않습니다. 내가 memcached 수 JDO 개체가 데이터 저장소 쿼리 결과를 원하지만 직렬화 할 수 없습니다. 그것에 대한 어떤 제안? – piyush