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 (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:

The methods to call are:
  • 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 in createCaches() and removeCaches() default methods.
      This is not meant to be called manually.
      Returns:
      A collection of Cacheable.SingleCacheConfigurations to manage
    • isCachingEnabled

      default boolean isCachingEnabled()
      Returns true if the cache is enabled
      The default implementation returns true.
      You can override this method to modify the behavior.
      Returns:
      true if the cache is enabled
    • getCacheManager

      Returns the instance of the implementation of AbstractCacheManager 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 class declares two caches, you can create the two methods:
      • Cache<String, Double> getCachePriceByProductId()
      • and Cache<Integer, Boolean> getCacheAvailabilityByProductIndex()
      which simply call this method, so as to have methods to retrieve the caches with more semantic.
      Type Parameters:
      K - The type of the keys in the cache
      V - 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.