@Concealed public class ExpiringCache<K,V> extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUCKET_COUNT
Default number of concurrent writes to support : 16 (must be a power of 2)
|
static int |
DEFAULT_BUCKET_INITIAL_SIZE
Default initial size of a bucket : 8 (must be power of 2)
|
static int |
DEFAULT_BUCKET_READ_COUNT_EXPIRATION_CHECK_INTERVAL
Default bucket read count interval at which a bucket's entries are additionally checked for expiration
(must be a power of 2 minus 1)
31 indicates that expiration check will occur when mReadCount for bucket is at 32,64,96,128,160,192,....
|
static long |
DEFAULT_ENTRY_VALIDITY_MS
Default validity time/duration of a bucket entry in milliseconds : 10 minutes
|
static int |
UNRESTRICTED_BUCKET_MAX_SIZE
max size of a bucket : 0 - unlimited
|
static int |
UNRESTRICTED_ENTRY_VALIDITY
cache entries will never expire due to age : 0 - unlimited
Note - cache entries may still be removed in the event a max bucket size is specified
|
Constructor and Description |
---|
ExpiringCache() |
ExpiringCache(int initialCacheSize) |
ExpiringCache(int bucketCount,
int bucketInitialSize,
int bucketMaxSize,
long entryValidityMS,
int readCountCheckInterval) |
ExpiringCache(int initialCacheSize,
int maxCacheSize,
long entryValidityMS) |
ExpiringCache(int initialCacheSize,
long entryValidityMS) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all entries from cache.
|
V |
get(K key)
Return value from cache linked to key; otherwise null.
|
V |
put(K key,
V value)
Store/replace object in cache, returning existing value if present
Supplying a value of null is equivalent to a remove operation
|
V |
remove(K key)
Remove entry from cache linked to key, returning entry value if non-expired; otherwise null.
|
long |
removeExpiredEntries()
Remove expired entries returning an approximation of the number of revised entries now cached
|
long |
size()
Return an approximation of how many entries are cached; Count may include entries potentially expired!
|
public static final int DEFAULT_BUCKET_COUNT
public static final int DEFAULT_BUCKET_INITIAL_SIZE
public static final long DEFAULT_ENTRY_VALIDITY_MS
public static final int DEFAULT_BUCKET_READ_COUNT_EXPIRATION_CHECK_INTERVAL
public static final int UNRESTRICTED_BUCKET_MAX_SIZE
public static final int UNRESTRICTED_ENTRY_VALIDITY
public ExpiringCache()
public ExpiringCache(int initialCacheSize)
public ExpiringCache(int initialCacheSize, long entryValidityMS)
public ExpiringCache(int initialCacheSize, int maxCacheSize, long entryValidityMS)
public ExpiringCache(int bucketCount, int bucketInitialSize, int bucketMaxSize, long entryValidityMS, int readCountCheckInterval)
public void clear()
public V put(K key, V value)
public V remove(K key)
public long removeExpiredEntries()
public long size()