views:

71

answers:

1

Using Memcache 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?

A: 

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

kodra