Class PortalCache<T>

  • Type Parameters:
    T - Type of the objects that will be cached.
    Direct Known Subclasses:
    InterfaceInstanceHtmlCache

    @StableMinor(version="14.1",
                 sinceVersion="4.0")
    public class PortalCache<T>
    extends Object
    Memory cache for portal objects. The identifier of a portal cache instance (given in the constructor) must be unique.
    Since:
    4.0.0
    Version:
    $Revision: 24683 $ $Date: 2021-08-23 18:55:58 -0300 (Mon, 23 Aug 2021) $
    • Field Detail

      • MAX_AGE_INFINITE

        public static final int MAX_AGE_INFINITE
        Value that indicates that there is no maximum age for entries in this cache.
        Since:
        4.2.1
        See Also:
        Constant Field Values
    • Constructor Detail

      • PortalCache

        public PortalCache​(String cacheId)
      • PortalCache

        public PortalCache​(String cacheId,
                           ICacheDataProvider<T> defaultCacheDataProvider)
        Creates a portal cache instance with the specified identifier and cache data provider.
        Parameters:
        cacheId - the cache identifier.
        defaultCacheDataProvider - the default cache data provider for this cache instance.
        Since:
        4.2.0
      • PortalCache

        public PortalCache​(String cacheId,
                           boolean autoClone)
    • Method Detail

      • clearAll

        public static void clearAll()
      • getId

        public String getId()
      • getMaxAgeSeconds

        public int getMaxAgeSeconds()
        Returns the current maximum age for entries in this cache.
        Returns:
        the maximum age in seconds, or MAX_AGE_INFINITE to indicate there is no maximum age.
        Since:
        4.2.1
      • setMaxAgeSeconds

        public void setMaxAgeSeconds​(int maxAgeSeconds)
        Sets the maximum age for entries in this cache. When the specified time has passed since an entry was added, it will no longer be returned by this cache.
        Parameters:
        maxAgeSeconds - the maximum age in seconds, or MAX_AGE_INFINITE to indicate there is no maximum age.
        Since:
        4.2.1
      • setDefaultCacheMultiDataProvider

        public PortalCache<T> setDefaultCacheMultiDataProvider​(ICacheMultiDataProvider<T> cacheMultiDataProvider)
        Sets the default cache multi-data provider. It will replace any previously set default ICacheDataProvider or ICacheMultiDataProvider in this cache.
        Parameters:
        cacheMultiDataProvider - the cache multi-data provider to set as default.
        Returns:
        this portal cache for operation chaining.
        Since:
        10.0.0
      • get

        public T get​(String key)
      • fetch

        public T fetch​(String key,
                       int maxAgeSeconds)
                throws PortalException
        Obtain the value associated with the specified key. If the value is not available in the cache, the default ICacheDataProvider or ICacheMultiDataProvider of this PortalCache is used to read the value, and the returned values are cached.
        Parameters:
        key - the key.
        maxAgeSeconds - the maximum age in seconds the returned value must have. If the specified time has passed since the entry found was added, it will be reloaded as if it did not exist. The value MAX_AGE_INFINITE indicates there is no maximum age limit.
        Returns:
        the value.
        Throws:
        UnsupportedOperationException - if there is no ICacheDataProvider or ICacheMultiDataProvider specified for this cache instance.
        PortalException - if the loadData method of the data provider used throws it.
        RuntimeException - any runtime exception thrown by the loadData method of the data provider used is thrown by this method.
        Since:
        14.0.0
      • fetch

        public T fetch​(String key,
                       int maxAgeSeconds,
                       String... groups)
                throws PortalException
        Obtains the value associated with the specified key and groups. If the value is not available in the cache, the ICacheDataProvider of this PortalCache is used to read the value, and it is cached.
        Parameters:
        key - the key.
        maxAgeSeconds - the maximum age in seconds the returned value must have. If the specified time has passed since the entry found was added, it will be reloaded as if it did not exist. The value MAX_AGE_INFINITE indicates there is no maximum age limit.
        groups - the groups associated with the key.
        Returns:
        the value.
        Throws:
        UnsupportedOperationException - if there is no ICacheDataProvider or ICacheMultiDataProvider specified for this cache instance.
        PortalException - if the loadData method of the data provider used throws it.
        RuntimeException - any runtime exception thrown by the loadData method of the data provider used is thrown by this method.
        Since:
        14.0.0
      • put

        public void put​(String key,
                        T value)
      • put

        public void put​(String key,
                        T value,
                        String... groups)
        Stores the key value along with the groups association.
        Parameters:
        key - the key.
        value - the key value.
        groups - one or more groups.
        Since:
        6.2.0
      • remove

        public void remove​(String key)
      • removeGroup

        public void removeGroup​(String group)
        Removes all keys associated with the given group.
        Parameters:
        group - the group identifier.
        Since:
        6.2.0
      • remove

        public void remove​(String key,
                           ITransaction transaction)
                    throws PortalException
        Removes an entry from the cache now and after the given transaction ends. The entry is not stored in the cache until the transaction ends (commits or rollsback).
        Parameters:
        key - the entry key.
        transaction - the transaction.
        Throws:
        PortalException
        Since:
        4.0.10
      • clear

        public void clear()
      • clear

        public void clear​(ITransaction transaction)
                   throws PortalException
        Clears the cache and disables it until the given transaction ends. No entry is stored in the cache until the transaction ends (commits or rollsback).
        Parameters:
        transaction - the transaction.
        Throws:
        PortalException
        Since:
        4.1.0
      • getSize

        public int getSize()
        Returns the number of entries currently stored in this cache.
        Returns:
        the number of entries currently stored in this cache.
        Since:
        4.0.11
      • getCapacity

        public int getCapacity()
        Returns the current capacity of this portal cache.
        Returns:
        the current capacity of this portal cache, in number of entries.
        Since:
        4.0.11
      • setCapacity

        public void setCapacity​(int newCapacity)
        Sets the capacity for this portal cache.
        Since:
        4.0.11
      • destroy

        public void destroy()
      • setReplicateOnPut

        protected void setReplicateOnPut()
        Experimental feature - Configure this cache to replicate an entry when it is added to the cache.
        Since:
        7.0.0