A builder of LoadingCache and Cache instances having any combination of the following features: automatic loading of entries into the cache least-recently-used eviction when a maximum size is exceeded time-based expiration of entries, measured since last access o
| 144 | |
| 145 | |
| 146 | @GwtCompatible(emulated = true) |
| 147 | public final class CacheBuilder<K, V> { |
| 148 | private static final int DEFAULT_INITIAL_CAPACITY = 16; |
| 149 | private static final int DEFAULT_CONCURRENCY_LEVEL = 4; |
| 150 | private static final int DEFAULT_EXPIRATION_NANOS = 0; |
| 151 | private static final int DEFAULT_REFRESH_NANOS = 0; |
| 152 | |
| 153 | static final Supplier<? extends StatsCounter> NULL_STATS_COUNTER = Suppliers.ofInstance(new StatsCounter() { |
| 154 | @Override |
| 155 | public void recordHits(int count) {} |
| 156 | |
| 157 | @Override |
| 158 | public void recordMisses(int count) {} |
| 159 | |
| 160 | @Override |
| 161 | public void recordLoadSuccess(long loadTime) {} |
| 162 | |
| 163 | @Override |
| 164 | public void recordLoadException(long loadTime) {} |
| 165 | |
| 166 | @Override |
| 167 | public void recordEviction() {} |
| 168 | |
| 169 | @Override |
| 170 | public CacheStats snapshot() { |
| 171 | return EMPTY_STATS; |
| 172 | } |
| 173 | }); |
| 174 | |
| 175 | static final CacheStats EMPTY_STATS = new CacheStats(0, 0, 0, 0, 0, 0); |
| 176 | |
| 177 | static final Supplier<StatsCounter> CACHE_STATS_COUNTER = new Supplier<StatsCounter>() { |
| 178 | @Override |
| 179 | public StatsCounter get() { |
| 180 | return new SimpleStatsCounter(); |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | enum NullListener implements RemovalListener<Object, Object> { |
| 185 | INSTANCE; |
| 186 | |
| 187 | @Override |
| 188 | public void onRemoval(RemovalNotification<Object, Object> notification) {} |
| 189 | } |
| 190 | |
| 191 | enum OneWeigher implements Weigher<Object, Object> { |
| 192 | INSTANCE; |
| 193 | |
| 194 | @Override |
| 195 | public int weigh(Object key, Object value) { |
| 196 | return 1; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | |
| 201 | static final Ticker NULL_TICKER = new Ticker() { |
| 202 | @Override |
| 203 | public long read() { |
nothing calls this directly
no test coverage detected