Package de.xima.fc.utils
Class XCacheUtils
- java.lang.Object
-
- de.xima.fc.utils.XCacheUtils
-
public class XCacheUtils extends Object
This helper class for the implementation of aCache
.- Since:
- 8.1.0
- Author:
- XIMA MEDIA GmbH
-
-
Constructor Summary
Constructors Constructor Description XCacheUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
org.ehcache.config.CacheConfiguration<K,V>createCache(Class<K> keyType, Class<V> valueType, long onHeapSize, long offHeapSize, long diskSize, long timeToExpire)
Creates a cache configuration with specified parameters for key and value types, sizes for on-heap, off-heap, and disk storage, as well as an expiration time.static <K,V>
Vupdate(org.ehcache.Cache<K,V> cache, K key, Supplier<V> supplier, UnaryOperator<V> updater)
Updates an entry within the specified cache.
-
-
-
Method Detail
-
createCache
public static <K,V> org.ehcache.config.CacheConfiguration<K,V> createCache(Class<K> keyType, Class<V> valueType, long onHeapSize, long offHeapSize, long diskSize, long timeToExpire)
Creates a cache configuration with specified parameters for key and value types, sizes for on-heap, off-heap, and disk storage, as well as an expiration time. This method allows for the creation of a customized cache configuration using Ehcache, specifying how much memory to use in different tiers (heap, off-heap, disk) and setting an expiration time for elements in the cache.- Type Parameters:
K
- the type of keys maintained by the cacheV
- the type of values to be stored in the cache- Parameters:
keyType
- theClass
object representing the type of keys, not nullvalueType
- theClass
object representing the type of values, not nullonHeapSize
- the maximum number of entries to store in the heapoffHeapSize
- the maximum amount of memory to use for the off-heapdiskSize
- the maximum amount of disk space to use for the disktimeToExpire
- the time after which the cache entries will expire- Returns:
- a
CacheConfiguration
instance configured with the specified parameters
-
update
public static <K,V> V update(org.ehcache.Cache<K,V> cache, K key, Supplier<V> supplier, UnaryOperator<V> updater)
Updates an entry within the specified cache. This method first checks if the cache contains an entry for the provided key. If an entry exists, it retrieves the value; otherwise, it obtans a new value by invoking the providedsupplier
. The value is then passed to the given updater function, which should return the new value. If theupdater
function returnsnull
the entry for the given key is removed from the cache.- Type Parameters:
K
- the type of keys by the cacheV
- the type of cached values- Parameters:
cache
- the cache to updatekey
- the key whose value is to be updatedsupplier
- aSupplier
that provides a new value when the key does not exist in the cacheupdater
- aUnaryOperator
that takes the current or supplied value and returns the updated value. If the result isnull
, the entry is removed.- Returns:
- the updated value
-
-