java.lang.Object
com.semanticcms.core.servlet.Cache
A caching cache, whether shared between requests or used within the scope of
a single request.
The thread safety will be the minimum needed for the expected usage.
- Thread safe for caches shared between requests.
- Thread safe for caches used in requests that may use concurrent subrequests.
- Not thread safe for per-request, no-subrequest caches. (in this case it's much like request attributes).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Cache.Callable<V,
Ex extends Exception> Constrains allowed exception type. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final boolean
Enables the page parent-child relationships verification. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract Object
getAttribute
(String key) Gets a cache attribute or null if not in cache.<V> V
getAttribute
(String key, Class<V> clazz) Gets a cache attribute or null if not in cache.abstract <V,
Ex extends Exception>
VgetAttribute
(String key, Class<V> clazz, Cache.Callable<? extends V, Ex> callable) Atomically checks the cache then calls the callable and adds.abstract <K,
V> Map <K, V> newMap()
Creates a new map that is suitable for the expected thread safety requirements.abstract <K,
V> Map <K, V> newMap
(int size) Creates a new map that is suitable for the expected thread safety requirements.abstract void
removeAttribute
(String key) Removes a cache attribute.abstract void
setAttribute
(String key, Object value) Sets a cache attribute.
-
Field Details
-
VERIFY_CACHE_PARENT_CHILD_RELATIONSHIPS
protected static final boolean VERIFY_CACHE_PARENT_CHILD_RELATIONSHIPSEnables the page parent-child relationships verification.This does not measurably affect performance; just leave it on.
- See Also:
-
-
Constructor Details
-
Cache
public Cache()
-
-
Method Details
-
newMap
Creates a new map that is suitable for the expected thread safety requirements. This map will itself be consistent with the thread safety guarantees of this cache overall. -
newMap
Creates a new map that is suitable for the expected thread safety requirements. This map will itself be consistent with the thread safety guarantees of this cache overall.- Parameters:
size
- the number of elements the map can hold before internal resizing. this is the actual size, no need to consider load factor or other nonsense.
-
setAttribute
Sets a cache attribute.- See Also:
-
getAttribute
Gets a cache attribute or null if not in cache. -
getAttribute
Gets a cache attribute or null if not in cache. The attribute is cast to the provided type. -
getAttribute
public abstract <V,Ex extends Exception> V getAttribute(String key, Class<V> clazz, Cache.Callable<? extends V, Ex> callable) throws ExAtomically checks the cache then calls the callable and adds. Note: It is possible the callable might be called and not used. If clean-up of unused callable is necessary, synchronize externally and use regular getAttribute/setAttribute in sequence.- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Throws:
Ex
-
removeAttribute
Removes a cache attribute.
-