Package io.jenkins.docker.client
Class UsageTrackingCache<K,V>
- java.lang.Object
-
- io.jenkins.docker.client.UsageTrackingCache<K,V>
-
- Type Parameters:
K
- The type of key by which cache entries can be indexed. This must implementObject.hashCode()
andObject.equals(Object)
.V
- The type of entry being cached.
public class UsageTrackingCache<K,V> extends Object
A cache that keep things until they haven't been used for a given duration. Things will be kept in the cache until they have been inactive for too long. Things will not be dropped from the cache while they are active, no matter how long that is.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
UsageTrackingCache.ExpiryHandler<K,V>
Callback API to handle things that are no longer in use when they eventually fall out of the cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cacheAndIncrementUsage(K key, V entry)
Puts an entry in the cache with a usage count of 1.void
decrementUsage(V entry)
Decrements the usage count on a cache entry, potentially removing it from active usage.V
getAndIncrementUsage(K key)
Looks up an existing entry in the cache.
-
-
-
Method Detail
-
getAndIncrementUsage
@CheckForNull public V getAndIncrementUsage(@NonNull K key)
Looks up an existing entry in the cache. If it finds an entry then it returns the entry and increments the usage count for that entry, and the caller MUST ensure thatdecrementUsage(Object)
is later called on the result. If it doesn't find an entry in the cache then it returns null (and the caller will most likely decide to callcacheAndIncrementUsage(Object, Object)
).- Parameters:
key
- The key used to look up the entry in the cache.- Returns:
- An existing cache entry, or null.
-
cacheAndIncrementUsage
public void cacheAndIncrementUsage(@NonNull K key, @NonNull V entry)
Puts an entry in the cache with a usage count of 1. The caller MUST ensure thatdecrementUsage(Object)
is later called on the entry that has been cached.- Parameters:
key
- The key used to look up the entry in the cache.entry
- The entry to be cached.
-
decrementUsage
public void decrementUsage(@NonNull V entry)
Decrements the usage count on a cache entry, potentially removing it from active usage. This method MUST be called once and only once for every time thatgetAndIncrementUsage(Object)
returned a non-null value and for every time thatcacheAndIncrementUsage(Object, Object)
was called.- Parameters:
entry
- The entry that is no longer in use.
-
-