I am using memcache to store only integer value with a key created with a string value. I didn't define expiration value to let the values hang on as long as they can which google documations say. But the problem is oldest item stays there 4 hours at most. Usually less than 2 hours only. Suddenly everything goes zero. Here is the code:
Key mKey=null;
MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
try {
mKey=KeyFactory.createKey("device",deviceNo);
if (memcache.get(mKey)==null) {
Query query = mgr.createQuery("select d.insDate from TrialCheck d where d.DeviceId = :deviceNo");
resultList.addAll(query.setParameter("deviceNo", deviceNo).getResultList());
if (resultList.size()<1){
resultList.add(0);
} else {
for (Integer d:resultList) {
memcache.put(mKey, d);
}
}
} else {
Integer installDate = (Integer) memcache.get(mKey);
resultList.add(installDate);
}
I read some posts saying that it is about instance going down but I couldn't see any correlation between the instance and memcache reset. Is this behaviour normal for shared memcache or the code has problem?
Aucun commentaire:
Enregistrer un commentaire