开发者

How to retrieve content (keys) of a Java JCache object in a Google AppEngine application

开发者 https://www.devze.com 2022-12-27 13:27 出处:网络
Using 开发者_如何学GoMemcache Java API (http://code.google.com/appengine/docs/java/memcache/overview.html)

Using 开发者_如何学GoMemcache Java API (http://code.google.com/appengine/docs/java/memcache/overview.html)

The JCache is not fully implemented and the methods values(), keySet() as well as entrySet() throw java.lang.UnsupportedOperationException

Anybody know of a workaround or have a working example using a lower-level API?


The only workaround I can see is to create another Cache instance with the goal to store under a known key an object containing keys, or any more complex structure. This structure is modified in the onPut() and onRemove() methods of the used CacheListener:

public void onRemove(Object key)
{
  LOG.log(Level.INFO, key.toString());
  Map<Integer, Date> realEstateIdByDate = (Map<Integer, Date>) keyCache.get("realEstateIdByDate");
  realEstateIdByDate.remove(key);
  keyCache.put("realEstateIdByDate", realEstateIdByDate);
}

@Override
public void onPut(Object object)
{
  LOG.log(Level.INFO, object.toString());
  Map<Integer, Date> realEstateIdByDate = (Map<Integer, Date>) keyCache.get("realEstateIdByDate");
  realEstateIdByDate.put(((RealEstateAd)object).getRealEstateId(), new Date());
  keyCache.put("realEstateIdByDate", realEstateIdByDate);
}

Any feedback more than welcome ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消