2. @cruftex
About Me
● Caching Fan(atic)
● 70+ answered questions on
StackOverflow about Caching
● JCache / JSR107 Contributor
● Author of cache2k
● General manager of a boutique software
engineering shop in Munich
3. @cruftex
Usual Suspects
● Legacy when finished, still Java 6
Missing features:
● No async support
● No transaction support
● No whatever…
● … but having lots of features is a problem, too!
4. @cruftex
Basic Semantics
● Store By Value (Default)
– Brain says: „It‘s for heap protection“
– Greg says: „Store By Value is anything else then
Store By Reference“
=> Basic semantics not exactly defined
=> In process caches need to copy values
=> No heap protection anyways
● Store By Reference (Optional)
5. @cruftex
remove()
Map:
V get(K key);
V put(K key, V value);
V remove(K key);
JCache:
V get(K key);
void put(K key, V value);
boolean remove(K key);
● Cache.put() does not expose the cache state
● Cache.remove() does expose the cache state
● Irritation: What is the meaning of the boolean in a
write through configuration?!
6. @cruftex
getAll()
Map<K,V> Cache.getAll(Set<K> keys);
● The Set interface is logical but impractical
● Is the map stable or will entries disappear when
removed or expired in the cache?
● How big can the map get?
● Copying values into a map is counterproductive to
the cache
7. @cruftex
Expiry Policy
interface ExpiryPolicy {
Duration getExpiryForCreation();
Duration getExpiryForUpdate();
Duration getExpiryForAccess();
}
● getExpiryForAccess() must get called on every access, but no variable
entry expiry. Slows down the most critical path of a cache hit.
● No combination TTL and TTI last returned duration is the expiry
● Duration is not the Java 8 Duration, but a JCache special
● What the meaning of duration, may the actually expiry lag or not?
● What is the time reference, before the call or after the call returned?
● The JCache TCK does no time related tests
=> not much tests on the expiry policy
8. @cruftex
Exception Handling
● The loader may throw a CacheLoaderException
● But: Every exception has to be wrapped in the
CacheLoaderException inside the cache implementation
(not totally clear, Spec and TCK diverge...)
● Leads to boiler plate try { } catch in the cache loader
interface CacheLoader{
V load(K key) throws CacheLoaderException;
}