Package org.ametys.core.util
Interface Cacheable
- All Known Implementing Classes:
AADUserDirectory
,AbstractCachingUserDirectory
,AbstractContentBasedSearchable
,CalendarContentSearchable
,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 (over
The methods to implement are:
The methods to call are:
This is the preferred way to manage the caching of elements (over
CachingComponent
), as it will use
the CacheManager 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
Modifier and TypeInterfaceDescriptionstatic final class
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
Creates the managed caches.default <K,
V> Cache<K, V> Gets the managed cache with the given id.Returns the instance of the implementation ofAbstractCacheManager
to use.Gets the managed caches.default boolean
Determines if the cache has a computable size.default boolean
Returnstrue
if the cache is enabled
The default implementation returnstrue
.default void
Removes the managed caches.
-
Method Details
-
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
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
Returns the instance of the implementation ofAbstractCacheManager
to use.
This is not meant to be called manually.- Returns:
- The
AbstractCacheManager
to bind
-
getCache
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
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
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
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.
-