Class CacheConfigUtil
java.lang.Object
fr.paris.lutece.portal.service.cache.CacheConfigUtil
Utility class for configuring and managing cache settings.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidReads the cache settings once for the caches created untilendStartupMemo(): 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>buildCacheConfigs(Map<String, String> properties) 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 URIcreateTempEhcacheConfigFile(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 implementingICacheConfigurationCustomizeradapt the configuration of a cache to the caching provider, for the settings that JCache cannot carry.determineCaheName(Set<String> keys) Determines the unique cache name prefixes from a set of property keys.static voidEnds the startup: each cache created afterwards (enabled in the back office) reads the current settingsstatic URIGenerates or updates the Ehcache configuration.static List<fr.paris.lutece.portal.service.cache.CacheConfigUtil.CacheConfig>Retrieves cache configurations.Builds the cache configuration map.static StringReturn the key of a datastore propertystatic <K,V> String getInfos(javax.cache.configuration.Configuration<K, V> conf) Returns cache configstatic StringgetJCacheName(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 booleangetStatusFromDataBase(String cacheName) Returns the cache status froms databasestatic booleangetStatusFromDataBase(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 booleanisDistributed(javax.cache.Cache<?, ?> cache) Tells whether a cache is shared by several instances of the webapp (any provider but Ehcache)static URIpreConfigureCacheManager(String uriValue, javax.cache.spi.CachingProvider cachingProvider, Properties properties) Pre-configures a cache manager with the given URI, caching provider, and properties.
-
Field Details
-
CACHE_LOGGER_NAME
- See Also:
-
-
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
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 untilendStartupMemo(): 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
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.CacheConfigobjects configured according to the given properties.
-
determineCaheName
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
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 nameconfiguration- 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 implementingICacheConfigurationCustomizeradapt 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 nameconfiguration- the configuration built by the coreprovider- 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
Returns the cache status froms database- Parameters:
cs- The cacheable service- Returns:
- The status
-
getStatusFromDataBase
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 namebDefault- the status of a cache that has no saved status- Returns:
- true if the cache is enabled
-
getDSKey
Return the key of a datastore property- Parameters:
strCacheName- The cacheable servicestrProperty- The property- Returns:
- The DS key
-
getInfos
Returns cache config- Parameters:
cache- The cache- Returns:
- Cache infos
-