public class SimpleProxyCache<K,V> extends Object implements ProxyCache<K,V>
| 构造器和说明 |
|---|
SimpleProxyCache(Cache<K,V> cache) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close()
Clean resources created by this cache.
|
V |
computeIfAbsent(K key,
Function<K,V> loader)
If there is a value associated with the key, return the value;
otherwise use the loader load the value and return, and then update the cache.
|
V |
computeIfAbsent(K key,
Function<K,V> loader,
boolean cacheNullWhenLoaderReturnNull)
If there is a value associated with the key, return the value;
otherwise use the loader load the value and return, and then update the cache.
|
V |
computeIfAbsent(K key,
Function<K,V> loader,
boolean cacheNullWhenLoaderReturnNull,
long expireAfterWrite,
TimeUnit timeUnit)
If there is a value associated with the key, return the value;
otherwise use the loader load the value and return, and then update the cache.
|
CacheConfig<K,V> |
config()
Get the config of this cache.
|
MultiGetResult<K,V> |
GET_ALL(Set<? extends K> keys)
Gets a collection of entries from the Cache.
|
V |
get(K key)
Gets an entry from the cache.
|
CacheGetResult<V> |
GET(K key)
Gets an entry from the cache.
|
Map<K,V> |
getAll(Set<? extends K> keys)
Gets a collection of entries from the Cache, returning them as Map of the values associated with
the set of keys requested.
|
Cache<K,V> |
getTargetCache() |
CacheResult |
PUT_ALL(Map<? extends K,? extends V> map)
Copies all of the entries from the specified map to the cache.
|
CacheResult |
PUT_ALL(Map<? extends K,? extends V> map,
long expireAfterWrite,
TimeUnit timeUnit)
Copies all of the entries from the specified map to the cache.
|
CacheResult |
PUT_IF_ABSENT(K key,
V value,
long expireAfterWrite,
TimeUnit timeUnit)
If the specified key is not already associated with a value, associate it with the given value.
|
void |
put(K key,
V value)
Associates the specified value with the specified key in the cache.
|
CacheResult |
PUT(K key,
V value)
Associates the specified value with the specified key in the cache.
|
void |
put(K key,
V value,
long expireAfterWrite,
TimeUnit timeUnit)
Associates the specified value with the specified key in the cache.
|
CacheResult |
PUT(K key,
V value,
long expireAfterWrite,
TimeUnit timeUnit)
Associates the specified value with the specified key in the cache.
|
void |
putAll(Map<? extends K,? extends V> map)
Copies all of the entries from the specified map to the cache.
|
void |
putAll(Map<? extends K,? extends V> map,
long expireAfterWrite,
TimeUnit timeUnit)
Copies all of the entries from the specified map to the cache.
|
boolean |
putIfAbsent(K key,
V value)
Atomically associates the specified key with the given value if it is not already associated with a value.
|
CacheResult |
REMOVE_ALL(Set<? extends K> keys)
Removes entries for the specified keys.
|
boolean |
remove(K key)
Removes the mapping for a key from this cache if it is present.
|
CacheResult |
REMOVE(K key)
Removes the mapping for a key from this cache if it is present.
|
void |
removeAll(Set<? extends K> keys)
Removes entries for the specified keys.
|
AutoReleaseLock |
tryLock(K key,
long expire,
TimeUnit timeUnit)
Use this cache attempt to acquire a exclusive lock specified by the key, this method will not block.
|
boolean |
tryLockAndRun(K key,
long expire,
TimeUnit timeUnit,
Runnable action)
Use this cache to try run an action exclusively.
|
<T> T |
unwrap(Class<T> clazz)
Provides a standard way to access the underlying concrete cache entry
implementation in order to provide access to further, proprietary features.
|
public CacheConfig<K,V> config()
Cachepublic Cache<K,V> getTargetCache()
getTargetCache 在接口中 ProxyCache<K,V>public V get(K key)
CacheIf the cache's builder has specified a CacheLoader and there is no association in the cache
, it will attempt to load the entry.
If error occurs during cache access, the method return null instead of throwing an exception.
get 在接口中 Cache<K,V>key - the key whose associated value is to be returnedCacheLoader,
Cache.GET(Object)public Map<K,V> getAll(Set<? extends K> keys)
CacheIf the cache's builder has specified a CacheLoader and there is no association in the cache
, it will attempt to load the entry.
If error occurs during cache access, the method will not throw an exception.
getAll 在接口中 Cache<K,V>keys - The keys whose associated values are to be returned.CacheLoader,
Cache.GET_ALL(Set)public void put(K key, V value)
CacheIf error occurs during cache access, the method will not throw an exception.
if the implementation supports asynchronous operation, the cache operation of this method is asynchronous.
put 在接口中 Cache<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keyCache.PUT(Object, Object)public void putAll(Map<? extends K,? extends V> map)
CacheIf error occurs during cache access, the method will not throw an exception.
if the implementation supports asynchronous operation, the cache operation of this method is asynchronous.
putAll 在接口中 Cache<K,V>map - mappings to be stored in this cache.Cache.PUT_ALL(Map)public boolean putIfAbsent(K key, V value)
CacheIf error occurs during cache access, the method will not throw an exception.
MultiLevelCache does not support this method.
putIfAbsent 在接口中 Cache<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keyCache.PUT_IF_ABSENT(Object, Object, long, TimeUnit)public boolean remove(K key)
CacheIf error occurs during cache access, the method will not throw an exception.
remove 在接口中 Cache<K,V>key - key whose mapping is to be removed from the cacheCache.REMOVE(Object)public void removeAll(Set<? extends K> keys)
CacheIf error occurs during cache access, the method will not throw an exception.
if the implementation supports asynchronous operation, the cache operation of this method is asynchronous.
removeAll 在接口中 Cache<K,V>keys - the keys to removeCache.REMOVE_ALL(Set)public <T> T unwrap(Class<T> clazz)
Cache
If the implementation does not support the specified class,
the IllegalArgumentException is thrown.
public AutoReleaseLock tryLock(K key, long expire, TimeUnit timeUnit)
Cache
try(AutoReleaseLock lock = cache.tryLock("MyKey",100, TimeUnit.SECONDS)){
if(lock != null){
// do something
}
}
MultiLevelCache will use the last level cache to support this operation.
tryLock 在接口中 Cache<K,V>key - lockKeyexpire - lock expire timetimeUnit - lock expire time unitCache.tryLockAndRun(Object, long, TimeUnit, Runnable)public boolean tryLockAndRun(K key, long expire, TimeUnit timeUnit, Runnable action)
CacheMultiLevelCache will use the last level cache to support this operation.
cache.tryLock("MyKey",100, TimeUnit.SECONDS),() -> {
//do something
});
tryLockAndRun 在接口中 Cache<K,V>key - lockKeyexpire - lock expire timetimeUnit - lock expire time unitaction - the action need to executepublic CacheGetResult<V> GET(K key)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage()/getValue() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
public MultiGetResult<K,V> GET_ALL(Set<? extends K> keys)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage()/getValue() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
public V computeIfAbsent(K key, Function<K,V> loader)
CachecomputeIfAbsent 在接口中 Cache<K,V>key - the keyloader - the value loaderCacheConfig.isCacheNullValue()public V computeIfAbsent(K key, Function<K,V> loader, boolean cacheNullWhenLoaderReturnNull)
CachecomputeIfAbsent 在接口中 Cache<K,V>key - the keyloader - the value loadercacheNullWhenLoaderReturnNull - true if null value returned by loader should put into cache use the keypublic V computeIfAbsent(K key, Function<K,V> loader, boolean cacheNullWhenLoaderReturnNull, long expireAfterWrite, TimeUnit timeUnit)
CachecomputeIfAbsent 在接口中 Cache<K,V>key - the keyloader - the value loadercacheNullWhenLoaderReturnNull - true if null value returned by loader should put into cache use the keyexpireAfterWrite - the TTL(time to live) of the KV associationtimeUnit - the time unit of expireAfterWritepublic void put(K key, V value, long expireAfterWrite, TimeUnit timeUnit)
CacheIf error occurs during cache access, the method will not throw an exception.
put 在接口中 Cache<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keyexpireAfterWrite - the TTL(time to live) of the KV associationtimeUnit - the time unit of expireAfterWriteCache.PUT(Object, Object, long, TimeUnit)public CacheResult PUT(K key, V value)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
public CacheResult PUT(K key, V value, long expireAfterWrite, TimeUnit timeUnit)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
public void putAll(Map<? extends K,? extends V> map, long expireAfterWrite, TimeUnit timeUnit)
CacheIf error occurs during cache access, the method will not throw an exception.
putAll 在接口中 Cache<K,V>map - mappings to be stored in this cache.expireAfterWrite - the TTL(time to live) of the KV associationtimeUnit - the time unit of expireAfterWriteCache.PUT_ALL(Map, long, TimeUnit)public CacheResult PUT_ALL(Map<? extends K,? extends V> map)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
public CacheResult PUT_ALL(Map<? extends K,? extends V> map, long expireAfterWrite, TimeUnit timeUnit)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
public CacheResult REMOVE(K key)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
public CacheResult REMOVE_ALL(Set<? extends K> keys)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
REMOVE_ALL 在接口中 Cache<K,V>keys - the keys to removepublic CacheResult PUT_IF_ABSENT(K key, V value, long expireAfterWrite, TimeUnit timeUnit)
Cacheif the implementation supports asynchronous operation, the cache access may not completed after this method return. The invoke of getResultCode()/isSuccess()/getMessage() on the result will block until cache operation is completed. Call future() method on the result will get a CompletionStage instance for asynchronous programming.
PUT_IF_ABSENT 在接口中 Cache<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keyexpireAfterWrite - the TTL(time to live) of the KV associationtimeUnit - the time unit of expireAfterWriteCopyright © 2013–2019. All rights reserved.