/** * Asynchronously computes or retrieves the value corresponding to {@code key}. * * @param key the non-null key whose value should be loaded * @param executor the executor with which the entry is asynchronously loaded * @return the future value associated with {@code key} */ @NonNull CompletableFuture<V> asyncLoad(@NonNull K key, @NonNull Executor executor);
/** * Returns a view of the entries stored in this cache as a synchronous {@link Cache}. A mapping is * not present if the value is currently being loaded. Modifications made to the synchronous cache * directly affect the asynchronous cache. If a modification is made to a mapping that is * currently loading, the operation blocks until the computation completes. * * @return a thread-safe synchronous view of this cache */ @NonNull Cache<K, V> synchronous(); }
/** * Returns a snapshot of this counter's values. Note that this may be an inconsistent view, as it * may be interleaved with update operations. * * @return a snapshot of this counter's values */ @NonNull CacheStats snapshot();
/** * Returns an accumulator that does not record any cache events. * * @return an accumulator that does not record metrics */ static @NonNull StatsCounter disabledStatsCounter() { return DisabledStatsCounter.INSTANCE; }
/** * Returns a statistics instance where no cache events have been recorded. * * @return an empty statistics instance */ @NonNull public static CacheStats empty() { return EMPTY_STATS; }
/** * Discards any cached values for the {@code keys}. The behavior of this operation is undefined * for an entry that is being loaded and is otherwise not present. * * @param keys the keys whose associated values are to be removed * @throws NullPointerException if the specified collection is null or contains a null element */ void invalidateAll(@NonNull Iterable<?> keys);
/** * Returns a current snapshot of this cache's cumulative statistics. All statistics are * initialized to zero, and are monotonically increasing over the lifetime of the cache. * <p> * Due to the performance penalty of maintaining statistics, some implementations may not record * the usage history immediately or at all. * * @return the current snapshot of the statistics of this cache */ @NonNull CacheStats stats();
/** * Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to * the map directly affect the cache. * <p> * Iterators from the returned map are at least <i>weakly consistent</i>: they are safe for * concurrent use, but if the cache is modified (including by eviction) after the iterator is * created, it is undefined which of the changes (if any) will be reflected in that iterator. * * @return a thread-safe view of this cache supporting all of the optional {@link Map} operations */ @NonNull ConcurrentMap<@NonNull K, @NonNull V> asMap();
/** * Returns an accumulator that suppresses and logs any exception thrown by the delegate * <tt>statsCounter</tt>. * * @param statsCounter the accumulator to delegate to * @return an accumulator that suppresses and logs any exception thrown by the delegate */ static @NonNull StatsCounter guardedStatsCounter(@NonNull StatsCounter statsCounter) { return new GuardedStatsCounter(statsCounter); } }
/** * Deletes the value corresponding to the {@code key} from the external resource. The cache will * communicate a delete when the entry is explicitly removed or evicted. * * @param key the non-null key whose value was removed * @param value the value associated with {@code key}, or {@code null} if collected * @param cause the reason for which the entry was removed * @throws RuntimeException or Error, in which case the mapping is unchanged */ void delete(@NonNull K key, @Nullable V value, @NonNull RemovalCause cause);
/** * Returns the weight of a cache entry. There is no unit for entry weights; rather they are simply * relative to each other. * * @param key the key to weigh * @param value the value to weigh * @return the weight of the entry; must be non-negative */ @NonNegative int weigh(@NonNull K key, @NonNull V value);
/** * @return the cause for which the entry was removed */ @NonNull public RemovalCause getCause() { return cause; }
/** * Returns the future associated with {@code key} in this cache, or {@code null} if there is no * cached future for {@code key}. * * @param key key whose associated value is to be returned * @return the current (existing or computed) future value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key * @throws NullPointerException if the specified key is null */ @Nullable CompletableFuture<V> getIfPresent(@NonNull Object key);
/** * Returns a Caffeine cache wrapped in a Guava {@link Cache} facade. * * @param builder the configured cache builder * @return a cache exposed under the Guava APIs */ @NonNull public static <K, V, K1 extends K, V1 extends V> Cache<K1, V1> build( @NonNull Caffeine<K, V> builder) { return new CaffeinatedGuavaCache<>(builder.build()); }
/** * Returns the value associated with the {@code key} in this cache, or {@code null} if there is no * cached value for the {@code key}. * * @param key the key whose associated value is to be returned * @return the value to which the specified key is mapped, or {@code null} if this map contains no * mapping for the key * @throws NullPointerException if the specified key is null */ @Nullable V getIfPresent(@NonNull Object key);
public JCacheExpiryPolicy(@NonNull Duration creation, @Nullable Duration update, @Nullable Duration access) { this.creation = requireNonNull(creation); this.update = update; this.access = access; }
public SoftValueReference(@NonNull Object keyReference, @Nullable V value, @Nullable ReferenceQueue<V> queue) { super(value, queue); this.keyReference = keyReference; }
/** * Removes a timer event for this entry if present. * * @param node the entry in the cache */ public void deschedule(@NonNull Node<K, V> node) { unlink(node); node.setNextInVariableOrder(null); node.setPreviousInVariableOrder(null); }