On Oct 15, 2007, at 9:32 , Chris Lamprecht wrote:
private Map<String, Object> getStuff(Collection<Integer> ids) {
StringBuilder buf = new StringBuilder(500);
for (int id : ids) {
buf.append("cacheditem:").append(id).append(' ');
}
String request = buf.toString().trim();
Map<String, Object> map = memcache.getBulk(request);
log.debug("Requested "+ids.size()+" items from cache, got
"+map.size()+" items back");
return map;
}
Ah. The bug is that I'm not validating keys in get bulk. You're
passing in a single key with spaces in it.
I'll make sure these are validated, but in the meantime, this is how
your code should look:
private Map<String, Object> getStuff(Collection<Integer> ids) {
Set<String> keys=new HashSet<String>();
for (int id : ids) {
keys.add("cacheditem:" + id);
}
Map<String, Object> map = memcache.getBulk(keys);
log.debug("Requested "+ids.size()+" items from cache, got
"+map.size()+" items back");
return map;
}
--
Dustin Sallings