Class SCacheImpl<T>

  • All Implemented Interfaces:
    SCache<T>

    public abstract class SCacheImpl<T>
    extends Object
    implements SCache<T>
    Author:
    kir
    • Constructor Detail

      • SCacheImpl

        public SCacheImpl​(net.sf.ehcache.Cache storage,
                          int timeToLive,
                          int timeToIdle,
                          Class<T> cachedItemsClass)
    • Method Detail

      • getName

        public String getName()
        Description copied from interface: SCache
        Name of the cache, as specified upon cache creation
        Specified by:
        getName in interface SCache<T>
      • read

        public T read​(@NotNull
                      String key)
        Description copied from interface: SCache
        Read cache value
        Specified by:
        read in interface SCache<T>
      • setAllowToReset

        public void setAllowToReset​(boolean allow)
        Description copied from interface: SCache
        Specify whether it is allowed to reset this cache from UI from the Diagnostic->Caches page.
        Specified by:
        setAllowToReset in interface SCache<T>
      • write

        public void write​(@NotNull
                          String key,
                          @Nullable
                          T value)
        Description copied from interface: SCache
        Put a value to cache with default time to live and time to idle
        Specified by:
        write in interface SCache<T>
        Parameters:
        key - cache key
        value - serializable value. If null, cached value is removed
      • write

        public void write​(@NotNull
                          String key,
                          @Nullable
                          T value,
                          int ttlSecs)
        Description copied from interface: SCache
        Put a value to cache with timeout (time to live)
        Specified by:
        write in interface SCache<T>
        Parameters:
        key - cache key
        value - serializable value. If null, cached value is removed
        ttlSecs - Time to live for cached value in seconds. 0 means no TTL (eternal)
      • fetch

        public T fetch​(String key,
                       Calculator<T> dataFetcher)
        Description copied from interface: SCache
        Get data from cache, if available. If not, obtain the data using dataFetcher and put them to the cache. The operation is blocking for a particular key. I.e. multiple fetch operations for a single key will wait until first of them will fill the cache.
        Specified by:
        fetch in interface SCache<T>
        Parameters:
        key - cache key
        dataFetcher - a procedure to obtain data if it is not found in the cache (data is put to the cache in this case)
        Returns:
        data from cache or from the dataFetcher
      • invalidate

        public void invalidate​(@NotNull
                               String key)
        Description copied from interface: SCache
        Delete cache value for particular key
        Specified by:
        invalidate in interface SCache<T>
      • flush

        public void flush()
        Description copied from interface: SCache
        Flush all the cache data to the disk
        Specified by:
        flush in interface SCache<T>
      • invalidateAll

        public void invalidateAll()
        Description copied from interface: SCache
        Invalidates (removes) all cache elements
        Specified by:
        invalidateAll in interface SCache<T>
      • isAlive

        public boolean isAlive()
      • dispose

        public abstract void dispose()
        Description copied from interface: SCache
        Flushes data on disk (if cache is persistable) and frees all of the resources associated with this cache.
        Specified by:
        dispose in interface SCache<T>