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 localL2Caching(); 025 026 /** 027 * Deprecated migrate to localL2Caching(). 028 */ 029 @Deprecated 030 default boolean isLocalL2Caching() { 031 return localL2Caching(); 032 } 033 034 /** 035 * Return all the cache regions. 036 */ 037 List<ServerCacheRegion> allRegions(); 038 039 /** 040 * Set the regions that are enabled. 041 * <p> 042 * Typically this is set on startup and at runtime (via dynamic configuration). 043 * </p> 044 * 045 * @param regions A region name or comma delimited list of region names. 046 */ 047 void enabledRegions(String regions); 048 049 /** 050 * Deprecated migrate to enabledRegions(). 051 */ 052 @Deprecated 053 default void setEnabledRegions(String regions) { 054 enabledRegions(regions); 055 } 056 057 /** 058 * Enable or disable all the cache regions. 059 */ 060 void allRegionsEnabled(boolean enabled); 061 062 /** 063 * Deprecated migrate to allRegionsEnabled(). 064 */ 065 @Deprecated 066 default void setAllRegionsEnabled(boolean enabled) { 067 allRegionsEnabled(enabled); 068 } 069 070 /** 071 * Return the cache region by name. Typically, to enable or disable the region. 072 */ 073 ServerCacheRegion region(String name); 074 075 @Deprecated 076 default ServerCacheRegion getRegion(String name) { 077 return region(name); 078 } 079 080 /** 081 * Return the cache for mapping natural keys to id values. 082 */ 083 ServerCache naturalKeyCache(Class<?> beanType); 084 085 @Deprecated 086 default ServerCache getNaturalKeyCache(Class<?> beanType) { 087 return naturalKeyCache(beanType); 088 } 089 090 /** 091 * Return the cache for beans of a particular type. 092 */ 093 ServerCache beanCache(Class<?> beanType); 094 095 @Deprecated 096 default ServerCache getBeanCache(Class<?> beanType) { 097 return beanCache(beanType); 098 } 099 100 /** 101 * Return the cache for associated many properties of a bean type. 102 */ 103 ServerCache collectionIdsCache(Class<?> beanType, String propertyName); 104 105 @Deprecated 106 default ServerCache getCollectionIdsCache(Class<?> beanType, String propertyName) { 107 return collectionIdsCache(beanType, propertyName); 108 } 109 110 /** 111 * Return the cache for query results of a particular type of bean. 112 */ 113 ServerCache queryCache(Class<?> beanType); 114 115 @Deprecated 116 default ServerCache getQueryCache(Class<?> beanType) { 117 return queryCache(beanType); 118 } 119 120 /** 121 * This clears both the bean and query cache for a given type. 122 */ 123 void clear(Class<?> beanType); 124 125 /** 126 * Clear all the caches. 127 */ 128 void clearAll(); 129 130 /** 131 * Clear all the local caches. 132 * <p> 133 * This is used when the L2 Cache is based on clustered near-caches (Like Ebean-K8s-L2Cache). 134 * It is not used when the L2 cache is a distributed cache such as HazelCast or Ignite etc. 135 */ 136 void clearAllLocal(); 137 138 /** 139 * Clear the local caches for this bean type. 140 * <p> 141 * This is used when the L2 Cache is based on clustered near-caches (Like Ebean-K8s-L2Cache). 142 * It is not used when the L2 cache is a distributed cache such as HazelCast or Ignite etc. 143 */ 144 void clearLocal(Class<?> beanType); 145}