Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cache should not call thorugh to underlying service when no operation…
…s are requested.
  • Loading branch information
stickfigure committed Nov 14, 2013
commit 3611f33d8a6cb3867535f321b8db30c89f71aa84
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.googlecode.objectify.cache;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

Expand All @@ -16,7 +17,8 @@

/**
* Subset of MemcacheService used by EntityMemcache, but smart enough to translate Key into the stringified
* version so that the memcache keys are intelligible.
* version so that the memcache keys are intelligible. Also guards against calling through to the underlying
* service when the operation is a no-op (ie, the collection of keys to operate on is empty).
*
* @author Jeff Schnitzer <jeff@infohazard.org>
*/
Expand Down Expand Up @@ -67,25 +69,40 @@ private Collection<String> stringify(Collection<Key> keys) {
}

public Map<Key, IdentifiableValue> getIdentifiables(Collection<Key> keys) {
if (keys.isEmpty())
return Collections.emptyMap();

Map<String, IdentifiableValue> map = service.getIdentifiables(stringify(keys));
return keyify(map);
}

public Map<Key, Object> getAll(Collection<Key> keys) {
if (keys.isEmpty())
return Collections.emptyMap();

Map<String, Object> map = service.getAll(stringify(keys));
return keyify(map);
}

public void putAll(Map<Key, Object> map) {
if (map.isEmpty())
return;

service.putAll(stringify(map));
}

public Set<Key> putIfUntouched(Map<Key, CasValues> map) {
if (map.isEmpty())
return Collections.emptySet();

Set<String> result = service.putIfUntouched(stringify(map));
return keyify(result);
}

public void deleteAll(Collection<Key> keys) {
if (keys.isEmpty())
return;

service.deleteAll(stringify(keys));
}

Expand Down