Class CacheConfigUtil

java.lang.Object
fr.paris.lutece.portal.service.cache.CacheConfigUtil

public class CacheConfigUtil extends Object
Utility class for configuring and managing cache settings.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Reads the cache settings once for the caches created until endStartupMemo(): to be called once the datastore holds its final settings (after the database scripts ran)
    static List<fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig>
    Builds a list of cache configurations from the given properties map.
    static <K, V> javax.cache.configuration.Configuration<K,V>
    completeConfiguration(String strCacheName, javax.cache.configuration.Configuration<K,V> configuration)
    Completes the JCache configuration of a cache with the expiry of its Lutece settings, so that a provider without a Lutece generated configuration (Hazelcast, Infinispan) expires the entries too.
    static URI
    createTempEhcacheConfigFile(List<fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig> cacheConfigs, fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig defaultCacheConfig)
    Creates a temporary Ehcache configuration file.
    static <K, V> javax.cache.configuration.Configuration<K,V>
    customizeConfiguration(String strCacheName, javax.cache.configuration.Configuration<K,V> configuration, javax.cache.spi.CachingProvider provider)
    Lets the CDI beans implementing ICacheConfigurationCustomizer adapt the configuration of a cache to the caching provider, for the settings that JCache cannot carry.
    static Set<String>
    Determines the unique cache name prefixes from a set of property keys.
    static void
    Ends the startup: each cache created afterwards (enabled in the back office) reads the current settings
    static URI
    Generates or updates the Ehcache configuration.
    static List<fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig>
    Retrieves cache configurations.
    static Map<String,String>
    Builds the cache configuration map.
    static String
    getDSKey(String strCacheName, String strProperty)
    Return the key of a datastore property
    static <K, V> String
    getInfos(javax.cache.configuration.Configuration<K,V> conf)
    Returns cache config
    static String
    getJCacheName(String strCacheName)
    Returns the name under which a cache is created in the JCache manager: the cache name without spaces, the name its settings are read under.
    static boolean
    Returns the cache status froms database
    static boolean
    getStatusFromDataBase(String cacheName, boolean bDefault)
    Returns the status of the cache saved in the database, or the given default when no status is saved yet (a cache created for the first time).
    static boolean
    isDistributed(javax.cache.Cache<?,?> cache)
    Tells whether a cache is shared by several instances of the webapp (any provider but Ehcache)
    static URI
    preConfigureCacheManager(String uriValue, javax.cache.spi.CachingProvider cachingProvider, Properties properties)
    Pre-configures a cache manager with the given URI, caching provider, and properties.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • CacheConfigUtil

      public CacheConfigUtil()
  • Method Details

    • preConfigureCacheManager

      public static URI preConfigureCacheManager(String uriValue, javax.cache.spi.CachingProvider cachingProvider, Properties properties) throws IOException
      Pre-configures a cache manager with the given URI, caching provider, and properties.
      Parameters:
      uriValue - The URI value for the cache configuration.
      cachingProvider - The caching provider.
      properties - The properties to configure the cache.
      Returns:
      The configured URI.
      Throws:
      IOException - If an I/O error occurs.
    • generateOrUpdateEhCacheConfig

      public static URI generateOrUpdateEhCacheConfig() throws IOException
      Generates or updates the Ehcache configuration.
      Returns:
      The URI of the generated or updated Ehcache configuration.
      Throws:
      IOException - If an I/O error occurs.
    • createTempEhcacheConfigFile

      public static URI createTempEhcacheConfigFile(List<fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig> cacheConfigs, fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig defaultCacheConfig) throws IOException
      Creates a temporary Ehcache configuration file.
      Parameters:
      cacheConfigs - The list of cache configurations.
      defaultCacheConfig - The default cache configuration.
      Returns:
      The URI of the created configuration file.
      Throws:
      IOException - If an I/O error occurs.
    • getCahesConfigs

      public static List<fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig> getCahesConfigs()
      Retrieves cache configurations.
      Returns:
      A list of cache configurations.
    • beginStartupMemo

      public static void beginStartupMemo()
      Reads the cache settings once for the caches created until endStartupMemo(): to be called once the datastore holds its final settings (after the database scripts ran)
    • endStartupMemo

      public static void endStartupMemo()
      Ends the startup: each cache created afterwards (enabled in the back office) reads the current settings
    • getConfigPropertiesWithPrefix

      public static Map<String,String> getConfigPropertiesWithPrefix()
      Builds the cache configuration map.
      Returns:
      A map of cache configurations.
    • buildCacheConfigs

      public static List<fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig> buildCacheConfigs(Map<String,String> properties)
      Builds a list of cache configurations from the given properties map.
      Parameters:
      properties - A map of properties where keys represent cache configuration parameters.
      Returns:
      A list of CacheConfigUtil.CacheConfig objects configured according to the given properties.
    • determineCaheName

      public static Set<String> determineCaheName(Set<String> keys)
      Determines the unique cache name prefixes from a set of property keys.
      Parameters:
      keys - A set of property keys.
      Returns:
      A set of unique cache name prefixes extracted from the keys.
    • getJCacheName

      public static String getJCacheName(String strCacheName)
      Returns the name under which a cache is created in the JCache manager: the cache name without spaces, the name its settings are read under.
      Parameters:
      strCacheName - the name of the cacheable service
      Returns:
      the JCache name
    • completeConfiguration

      public static <K, V> javax.cache.configuration.Configuration<K,V> completeConfiguration(String strCacheName, javax.cache.configuration.Configuration<K,V> configuration)
      Completes the JCache configuration of a cache with the expiry of its Lutece settings, so that a provider without a Lutece generated configuration (Hazelcast, Infinispan) expires the entries too. Ehcache templates override this expiry with the same settings. A configuration that sets its own expiry is kept. Immutable values are stored by reference.
      Parameters:
      strCacheName - the cache name
      configuration - the configuration given by the cacheable service
      Returns:
      the configuration to create the cache with
    • customizeConfiguration

      public static <K, V> javax.cache.configuration.Configuration<K,V> customizeConfiguration(String strCacheName, javax.cache.configuration.Configuration<K,V> configuration, javax.cache.spi.CachingProvider provider)
      Lets the CDI beans implementing ICacheConfigurationCustomizer adapt the configuration of a cache to the caching provider, for the settings that JCache cannot carry. A customizer that fails is skipped and logged.
      Parameters:
      strCacheName - the cache name
      configuration - the configuration built by the core
      provider - the caching provider of the cache manager
      Returns:
      the configuration to create the cache with
    • isDistributed

      public static boolean isDistributed(javax.cache.Cache<?,?> cache)
      Tells whether a cache is shared by several instances of the webapp (any provider but Ehcache)
      Parameters:
      cache - the cache
      Returns:
      true when the cache is not local to this instance
    • getStatusFromDataBase

      public static boolean getStatusFromDataBase(String cacheName)
      Returns the cache status froms database
      Parameters:
      cs - The cacheable service
      Returns:
      The status
    • getStatusFromDataBase

      public static boolean getStatusFromDataBase(String cacheName, boolean bDefault)
      Returns the status of the cache saved in the database, or the given default when no status is saved yet (a cache created for the first time). A status chosen in the back office is thus kept across restarts.
      Parameters:
      cacheName - the cache name
      bDefault - the status of a cache that has no saved status
      Returns:
      true if the cache is enabled
    • getDSKey

      public static String getDSKey(String strCacheName, String strProperty)
      Return the key of a datastore property
      Parameters:
      strCacheName - The cacheable service
      strProperty - The property
      Returns:
      The DS key
    • getInfos

      public static <K, V> String getInfos(javax.cache.configuration.Configuration<K,V> conf)
      Returns cache config
      Parameters:
      cache - The cache
      Returns:
      Cache infos