Package org.ametys.core.util
Interface Cacheable
-
- All Known Implementing Classes:
AADUserDirectory
,AbstractCachingUserDirectory
,AbstractContentBasedSearchable
,ContentSearchable
,CourseSearchable
,JdbcGroupDirectory
,JdbcUserDirectory
,LdapGroupDirectory
,LdapUserDirectory
,PrivateContentSearchable
,ProgramSearchable
public interface Cacheable
Trait for easily cache some elements, in multiple Caches if necessary.
This is the preferred way to manage the caching of elements (overCachingComponent
), as it will use theCacheManager mechanism
, and as it is an interface, it will not interfere in the class hierarchy of the implementing component.
The methods to implement are:getManagedCaches()
: for describing the managed caches;getCacheManager()
: for binding the reference ofAbstractCacheManager
;isCachingEnabled()
: for implementing the potential business logic to determine if the caching is enabled.
The methods to call are:createCaches()
: for creating the managed caches;removeCaches()
: for removing the managed caches;getCache(java.lang.String)
: for getting a reference to a managed cache.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Cacheable.SingleCacheConfiguration
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
createCaches()
Creates the managed caches.default <K,V>
Cache<K,V>getCache(String cacheId)
Gets the managed cache with the given id.AbstractCacheManager
getCacheManager()
Returns the instance of the implementation ofAbstractCacheManager
to use.Collection<Cacheable.SingleCacheConfiguration>
getManagedCaches()
Gets the managed caches.default boolean
hasComputableSize()
Determines if the cache has a computable size.default boolean
isCachingEnabled()
Returnstrue
if the cache is enabled
The default implementation returnstrue
.default void
removeCaches()
Removes the managed caches.
-
-
-
Method Detail
-
getManagedCaches
Collection<Cacheable.SingleCacheConfiguration> getManagedCaches()
Gets the managed caches.
This is meant to be implemented in order to describe the managed caches and automatically create and remove the corresponding caches increateCaches()
andremoveCaches()
default methods.
This is not meant to be called manually.- Returns:
- A collection of
Cacheable.SingleCacheConfiguration
s to manage
-
isCachingEnabled
default boolean isCachingEnabled()
Returnstrue
if the cache is enabled
The default implementation returnstrue
.
You can override this method to modify the behavior.- Returns:
true
if the cache is enabled
-
getCacheManager
AbstractCacheManager getCacheManager()
Returns the instance of the implementation ofAbstractCacheManager
to use.
This is not meant to be called manually.- Returns:
- The
AbstractCacheManager
to bind
-
getCache
default <K,V> Cache<K,V> getCache(String cacheId)
Gets the managed cache with the given id.
It is advised to create its own business methods which call this method in order to retrieve the caches.
For instance, if the implementing classdeclares
two caches, you can create the two methods:Cache<String, Double> getCachePriceByProductId()
- and
Cache<Integer, Boolean> getCacheAvailabilityByProductIndex()
- Type Parameters:
K
- The type of the keys in the cacheV
- The type of the values in the cache- Parameters:
cacheId
- The cache id- Returns:
- The managed
Cache
-
createCaches
default void createCaches()
Creates the managed caches.
This is meant to be called manually, at the beginning of the lifecycle of the implementing class, in order to create and initialize the corresponding caches.
This is not meant to be overridden.
-
removeCaches
default void removeCaches()
Removes the managed caches.
This is meant to be called manually, at the end of the lifecycle of the implementing class, in order to remove the corresponding caches.
This is not meant to be overridden.
-
hasComputableSize
default boolean hasComputableSize()
Determines if the cache has a computable size. This operation can be very slow.- Returns:
true
if we can compute the size on the cache.
-
-