public abstract class ConcurrentCacheStoreBase<T> extends Object
Modifier | Constructor and Description |
---|---|
protected |
ConcurrentCacheStoreBase()
Initialize the cache store.
|
Modifier and Type | Method and Description |
---|---|
protected abstract T |
createEntryValue(CacheStoreKeyBase key)
Concrete class must implement this method to create a cache value object.
|
T |
get(CacheStoreKeyBase key)
Get a value from the cache store.
|
T |
remove(CacheStoreKeyBase key)
Remove a value from the cache
|
int |
size()
Get size of the cache table.
|
String |
toString() |
protected ConcurrentCacheStoreBase()
public final T get(CacheStoreKeyBase key)
The implementation is thread-safe. The API looks like a "read" access, but when the cache doesn't have a hit, it will write an entry to the cache table. The first attempt queries the cache, so the read-lock allows parallelized read if no other thread is writing the cache. If there's no hit, the second attempt is to create a valid entry, store it in the cache and return it. This requires upgrading the read-lock to a write-lock.
key
- cache keypublic final T remove(CacheStoreKeyBase key)
key
- cache keypublic int size()
protected abstract T createEntryValue(CacheStoreKeyBase key)
get(CacheStoreKeyBase)
is
responsible for reading and writing the cache table.key
- cache keyCopyright © 2016 The Apache Software Foundation. All rights reserved.