Assigned
Status Update
Comments
mi...@gmail.com <mi...@gmail.com> #2
i meant the following:
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class AppEngineCache implements Map {
protected MemcacheService cache = MemcacheServiceFactory.getMemcacheService();
public int size() {
return new Long(cache.getStatistics().getItemCount()).intValue();
}
public boolean isEmpty() {
return cache.getStatistics().getItemCount() != 0;
}
public boolean containsKey(Object key) {
return cache.contains(key);
}
public boolean containsValue(Object value) {
throw new UnsupportedOperationException("containsValue() is not supported in
App Engine");
}
public Object get(Object key) {
return cache.get(key);
}
public Object put(Object key, Object value) {
cache.put(key, value);
return value;
}
public Object remove(Object key) {
Object value = cache.get(key);
cache.delete(key);
return value;
}
public void putAll(Map m) {
cache.putAll(m);
}
public void clear() {
cache.clearAll();
}
public Set keySet() {
throw new UnsupportedOperationException("keySet() is not supported in App
Engine");
}
public Collection values() {
throw new UnsupportedOperationException("values() is not supported in App
Engine");
}
public Set entrySet() {
throw new UnsupportedOperationException("entrySet() is not supported in App
Engine");
}
}
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class AppEngineCache implements Map {
protected MemcacheService cache = MemcacheServiceFactory.getMemcacheService();
public int size() {
return new Long(cache.getStatistics().getItemCount()).intValue();
}
public boolean isEmpty() {
return cache.getStatistics().getItemCount() != 0;
}
public boolean containsKey(Object key) {
return cache.contains(key);
}
public boolean containsValue(Object value) {
throw new UnsupportedOperationException("containsValue() is not supported in
App Engine");
}
public Object get(Object key) {
return cache.get(key);
}
public Object put(Object key, Object value) {
cache.put(key, value);
return value;
}
public Object remove(Object key) {
Object value = cache.get(key);
cache.delete(key);
return value;
}
public void putAll(Map m) {
cache.putAll(m);
}
public void clear() {
cache.clearAll();
}
public Set keySet() {
throw new UnsupportedOperationException("keySet() is not supported in App
Engine");
}
public Collection values() {
throw new UnsupportedOperationException("values() is not supported in App
Engine");
}
public Set entrySet() {
throw new UnsupportedOperationException("entrySet() is not supported in App
Engine");
}
}
Description
would be nice if it implements Map.
The advantages:
1. in our app, we may inject a MemcacheService as a Map without depending
on GAE's API.
2. it provides more standard interface that most of us Java developers are
familiar
3. When using languages that provides feature for Map, e.g. Groovy, it
makes the use of Memcache much easier.
MemcacheService could still have its own interface when people want to use
the low-level API directly. And some interface has to be renamed, e.g.
contains() -> containsKey(). For the interface that GAE doesn't support,
e.g. containsValue(), it may just throw exception like in JCache API.