java.lang.Object
com.semanticcms.core.servlet.Cache

public abstract class Cache extends Object
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.

  1. Thread safe for caches shared between requests.
  2. Thread safe for caches used in requests that may use concurrent subrequests.
  3. Not thread safe for per-request, no-subrequest caches. (in this case it's much like request attributes).
  • Field Details

    • VERIFY_CACHE_PARENT_CHILD_RELATIONSHIPS

      protected static final boolean VERIFY_CACHE_PARENT_CHILD_RELATIONSHIPS
      Enables 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

      public abstract <K, V> Map<K,V> 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

      public abstract <K, V> Map<K,V> newMap(int size)
      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

      public abstract void setAttribute(String key, Object value)
      Sets a cache attribute.
      See Also:
    • getAttribute

      public abstract Object getAttribute(String key)
      Gets a cache attribute or null if not in cache.
    • getAttribute

      public <V> V getAttribute(String key, Class<V> clazz)
      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 Ex
      Atomically 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

      public abstract void removeAttribute(String key)
      Removes a cache attribute.