Class AbstractCacheableService<K,V>

java.lang.Object
fr.paris.lutece.portal.service.cache.AbstractCacheableService<K,V>
Type Parameters:
K - the type of keys maintained by the cache
V - the type of cached values
All Implemented Interfaces:
CacheableService<K,V>, Lutece107Cache<K,V>, LuteceService, Closeable, Serializable, AutoCloseable, Iterable<javax.cache.Cache.Entry<K,V>>, javax.cache.Cache<K,V>
Direct Known Subclasses:
BaseUserPreferencesCacheService, Default107Cache, LinksIncludeCacheService, LuteceUserCacheService, PageCacheService, PathCacheService, PortletCacheService, ResourceService

public abstract class AbstractCacheableService<K,V> extends Object implements Lutece107Cache<K,V>
Base Lutece implementation of the Cache using JCache (JSR-107) and cacheable service. This class implements the JCache (JSR-107) cache API and provides the service for enabling and disabling caches from an administration interface.
See Also:
  • Constructor Details

    • AbstractCacheableService

      public AbstractCacheableService()
  • Method Details

    • initCache

      public void initCache()
      Init & create the cache. Should be called by the class (cache) that extends AbstractCacheableService during its initialization.
    • initCache

      public void initCache(String strCacheName)
      Init & create the cache. Should be called by the class (cache) that extends AbstractCacheableService during its initialization.
      Parameters:
      strCacheName - The cache name
    • initCache

      public void initCache(String strCacheName, boolean bEnable)
      Init & create the cache. Should be called by the class (cache) that extends AbstractCacheableService during its initialization.
      Parameters:
      strCacheName - The cache name
      bEnable - enable cache
    • putInCache

      @Deprecated public void putInCache(K strKey, V object)
      Deprecated.
      Put an object into the cache. This method will be removed in the next version. Use put(K, V) instead.
      Parameters:
      strKey - The key of the object to put into the cache
      object - The object to put into the cache
    • getFromCache

      @Deprecated public V getFromCache(K strKey)
      Deprecated.
      Gets an object from the cache. This method will be removed in the next version. Use get(K) instead.
      Parameters:
      strKey - The key of the object to retrieve from the cache
      Returns:
      The object from the cache
    • isCacheEnable

      public boolean isCacheEnable()
      Gets the current cache status.
      Specified by:
      isCacheEnable in interface CacheableService<K,V>
      Returns:
      true if the cache is enabled, otherwise false
    • getCacheSize

      public int getCacheSize()
      Gets the number of items currently in the cache.
      Specified by:
      getCacheSize in interface CacheableService<K,V>
      Returns:
      the number of items currently in the cache
    • enableCache

      public void enableCache(boolean bEnable)
      Enables or disables the cache.
      Specified by:
      enableCache in interface CacheableService<K,V>
      Parameters:
      bEnable - true to enable, false to disable
    • resetCache

      public void resetCache()
      Resets the cache.
      Specified by:
      resetCache in interface CacheableService<K,V>
    • getKeys

      public List<K> getKeys()
      Gets all keys in the cache.
      Specified by:
      getKeys in interface CacheableService<K,V>
      Returns:
      a list of all keys in the cache
    • getInfos

      public String getInfos()
      Returns cache information.
      Specified by:
      getInfos in interface CacheableService<K,V>
      Returns:
      cache information
    • removeKey

      @Deprecated public void removeKey(K strKey)
      Deprecated.
      Remove a key from the cache. This method will be removed in the next version. Use remove(K) instead.
      Parameters:
      strKey - The key to remove
    • get

      public V get(K key)
      Specified by:
      get in interface javax.cache.Cache<K,V>
    • getAll

      public Map<K,V> getAll(Set<? extends K> keys)
      Specified by:
      getAll in interface javax.cache.Cache<K,V>
    • containsKey

      public boolean containsKey(K key)
      Specified by:
      containsKey in interface javax.cache.Cache<K,V>
    • loadAll

      public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, javax.cache.integration.CompletionListener completionListener)
      Specified by:
      loadAll in interface javax.cache.Cache<K,V>
    • put

      public void put(K key, V value)
      Specified by:
      put in interface javax.cache.Cache<K,V>
    • getAndPut

      public V getAndPut(K key, V value)
      Specified by:
      getAndPut in interface javax.cache.Cache<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> map)
      Specified by:
      putAll in interface javax.cache.Cache<K,V>
    • putIfAbsent

      public boolean putIfAbsent(K key, V value)
      Specified by:
      putIfAbsent in interface javax.cache.Cache<K,V>
    • remove

      public boolean remove(K key)
      Specified by:
      remove in interface javax.cache.Cache<K,V>
    • remove

      public boolean remove(K key, V oldValue)
      Specified by:
      remove in interface javax.cache.Cache<K,V>
    • getAndRemove

      public V getAndRemove(K key)
      Specified by:
      getAndRemove in interface javax.cache.Cache<K,V>
    • replace

      public boolean replace(K key, V oldValue, V newValue)
      Specified by:
      replace in interface javax.cache.Cache<K,V>
    • replace

      public boolean replace(K key, V value)
      Specified by:
      replace in interface javax.cache.Cache<K,V>
    • getAndReplace

      public V getAndReplace(K key, V value)
      Specified by:
      getAndReplace in interface javax.cache.Cache<K,V>
    • removeAll

      public void removeAll(Set<? extends K> keys)
      Specified by:
      removeAll in interface javax.cache.Cache<K,V>
    • removeAll

      public void removeAll()
      Specified by:
      removeAll in interface javax.cache.Cache<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface javax.cache.Cache<K,V>
    • getConfiguration

      public <C extends javax.cache.configuration.Configuration<K, V>> C getConfiguration(Class<C> clazz)
      Specified by:
      getConfiguration in interface javax.cache.Cache<K,V>
    • invoke

      public <T> T invoke(K key, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... arguments)
      Specified by:
      invoke in interface javax.cache.Cache<K,V>
    • invokeAll

      public <T> Map<K,javax.cache.processor.EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, javax.cache.processor.EntryProcessor<K,V,T> entryProcessor, Object... arguments)
      Specified by:
      invokeAll in interface javax.cache.Cache<K,V>
    • getCacheManager

      public javax.cache.CacheManager getCacheManager()
      Specified by:
      getCacheManager in interface javax.cache.Cache<K,V>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface javax.cache.Cache<K,V>
      Specified by:
      close in interface Closeable
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface javax.cache.Cache<K,V>
    • unwrap

      public <T> T unwrap(Class<T> clazz)
      Specified by:
      unwrap in interface javax.cache.Cache<K,V>
    • registerCacheEntryListener

      public void registerCacheEntryListener(javax.cache.configuration.CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
      Specified by:
      registerCacheEntryListener in interface javax.cache.Cache<K,V>
    • deregisterCacheEntryListener

      public void deregisterCacheEntryListener(javax.cache.configuration.CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
      Specified by:
      deregisterCacheEntryListener in interface javax.cache.Cache<K,V>
    • iterator

      public Iterator<javax.cache.Cache.Entry<K,V>> iterator()
      Specified by:
      iterator in interface javax.cache.Cache<K,V>
      Specified by:
      iterator in interface Iterable<K>
    • setCache

      public void setCache(javax.cache.Cache<K,V> cache)
      Set cache.
      Parameters:
      cache - the cache to set
    • getCache

      public javax.cache.Cache<K,V> getCache()
      Return a cache object.
      Returns:
      cache object
    • isPreventGlobalReset

      public boolean isPreventGlobalReset()
      Description copied from interface: CacheableService
      Can the cache be reset by automatic caches resets
      Specified by:
      isPreventGlobalReset in interface CacheableService<K,V>
      Returns:
      true is the cache can be reset by automatic / massive caches resets, false otherwise
    • isRequired

      public boolean isRequired()
      Is the cache required by the webapp: it holds data that are not read again elsewhere (the loaded plugins, a notification shared by the instances...). A required cache is always enabled, whatever the status saved in the database or chosen in the back office.
      Specified by:
      isRequired in interface CacheableService<K,V>
      Returns:
      true if the cache can never be disabled
    • isPreventReset

      public boolean isPreventReset()
      Can the cache be emptied: a cache whose entries cannot be rebuilt on a cache miss is never reset, neither by a global reset nor by its own reset.
      Specified by:
      isPreventReset in interface CacheableService<K,V>
      Returns:
      true if the cache can never be reset