001package io.ebean.cache;
002
003import io.ebean.meta.MetricVisitor;
004
005import java.util.List;
006
007/**
008 * The cache service for server side caching of beans and query results.
009 */
010public interface ServerCacheManager {
011
012  /**
013   * Visit the metrics for all the server caches.
014   */
015  void visitMetrics(MetricVisitor visitor);
016
017  /**
018   * Return true if the L2 caching is local.
019   * <p>
020   * Local L2 caching means that the cache updates should occur in foreground
021   * rather than background processing.
022   * </p>
023   */
024  boolean isLocalL2Caching();
025
026  /**
027   * Return all the cache regions.
028   */
029  List<ServerCacheRegion> allRegions();
030
031  /**
032   * Set the regions that are enabled.
033   * <p>
034   * Typically this is set on startup and at runtime (via dynamic configuration).
035   * </p>
036   *
037   * @param regions A region name or comma delimited list of region names.
038   */
039  void setEnabledRegions(String regions);
040
041  /**
042   * Enable or disable all the cache regions.
043   */
044  void setAllRegionsEnabled(boolean enabled);
045
046  /**
047   * Return the cache region by name. Typically to enable or disable the region.
048   */
049  ServerCacheRegion getRegion(String name);
050
051  /**
052   * Return the cache for mapping natural keys to id values.
053   */
054  ServerCache getNaturalKeyCache(Class<?> beanType);
055
056  /**
057   * Return the cache for beans of a particular type.
058   */
059  ServerCache getBeanCache(Class<?> beanType);
060
061  /**
062   * Return the cache for associated many properties of a bean type.
063   */
064  ServerCache getCollectionIdsCache(Class<?> beanType, String propertyName);
065
066  /**
067   * Return the cache for query results of a particular type of bean.
068   */
069  ServerCache getQueryCache(Class<?> beanType);
070
071  /**
072   * This clears both the bean and query cache for a given type.
073   */
074  void clear(Class<?> beanType);
075
076  /**
077   * Clear all the caches.
078   */
079  void clearAll();
080
081  /**
082   * Clear all the local caches.
083   * <p>
084   * This is used when the L2 Cache is based on clustered near-caches (Like Ebean-K8s-L2Cache).
085   * It is not used when the L2 cache is a distributed cache such as HazelCast or Ignite etc.
086   */
087  void clearAllLocal();
088
089  /**
090   * Clear the local caches for this bean type.
091   * <p>
092   * This is used when the L2 Cache is based on clustered near-caches (Like Ebean-K8s-L2Cache).
093   * It is not used when the L2 cache is a distributed cache such as HazelCast or Ignite etc.
094   */
095  void clearLocal(Class<?> beanType);
096}