Class SynchronousExternalCache<V>
- java.lang.Object
-
- com.atlassian.confluence.impl.vcache.SynchronousExternalCache<V>
-
public class SynchronousExternalCache<V> extends Object
A wrapper around a VCache external cache which provides synchronous, opverloaded operations for convenience and predictable error handling.- Since:
- 5.10
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSynchronousExternalCache.CacheException
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Optional<V>get(String key)Get an entry from the cache.Vget(String key, com.atlassian.util.concurrent.Supplier<V> valueLoader)Get an entry from the cache.Optional<V>get(String key, Function<Throwable,Optional<V>> onError)Get an entry from the cache.<R> Rget(String key, Function<Optional<V>,R> onSuccess, Function<Throwable,R> onError)Get an entry from the cache.booleanput(String key, V value)Deprecated.since 7.5 Useget(String, Supplier)to populate cache values.booleanput(String key, V value, com.atlassian.vcache.PutPolicy putPolicy)Deprecated.since 7.5 Useget(String, Supplier)to populate cache values.booleanput(String key, V value, com.atlassian.vcache.PutPolicy putPolicy, Consumer<Throwable> onError)Deprecated.since 7.5 Useget(String, Supplier)to populate cache values.booleanput(String key, V value, com.atlassian.vcache.PutPolicy putPolicy, Function<Throwable,Boolean> onError)Deprecated.since 7.5 Useget(String, Supplier)to populate cache values.voidremove(String key)Removes a cache entry.voidremove(String key, Consumer<Throwable> onError)Removes a cache entry.voidremoveAll()Remove all entries from the cachestatic <C extends T,T extends Serializable>
com.atlassian.vcache.Marshaller<C>serializableMarshaller(Class<T> type)A utility method for creating a VCache marshaller for the given serializable type, when that type also has a generic signature, e.g.static <C extends com.atlassian.vcache.ExternalWriteOperationsUnbuffered<V> & com.atlassian.vcache.ExternalCache<V>,V>
SynchronousExternalCache<V>synchronous(C cache)Create a wrapper around the given cache.static <C extends com.atlassian.vcache.ExternalWriteOperationsUnbuffered<V> & com.atlassian.vcache.ExternalCache<V>,V>
SynchronousExternalCache<V>synchronous(com.atlassian.util.concurrent.Supplier<C> cacheRef)Create a wrapper around the given cache supplier.static <V> SynchronousExternalCache<V>synchronousStableReadExternalCache(com.atlassian.vcache.VCacheFactory cacheFactory, String cacheName, com.atlassian.vcache.Marshaller<V> marshaller)Create a wrapper around aStableReadExternalCachewith the given name and marshaller.static <V> SynchronousExternalCache<V>synchronousStableReadExternalCache(com.atlassian.vcache.VCacheFactory cacheFactory, String cacheName, com.atlassian.vcache.Marshaller<V> marshaller, com.atlassian.vcache.ExternalCacheSettingsBuilder cacheSettingsBuilder)Create a wrapper around aStableReadExternalCachewith the given name, marshaller and cache settings.static <V extends Serializable>
SynchronousExternalCache<V>synchronousStableReadExternalCache(com.atlassian.vcache.VCacheFactory cacheFactory, String cacheName, Class<V> valueType)Create a wrapper around aStableReadExternalCachewith the given name and value type.
-
-
-
Method Detail
-
synchronousStableReadExternalCache
public static <V> SynchronousExternalCache<V> synchronousStableReadExternalCache(com.atlassian.vcache.VCacheFactory cacheFactory, String cacheName, com.atlassian.vcache.Marshaller<V> marshaller)
Create a wrapper around aStableReadExternalCachewith the given name and marshaller.
-
synchronousStableReadExternalCache
public static <V extends Serializable> SynchronousExternalCache<V> synchronousStableReadExternalCache(com.atlassian.vcache.VCacheFactory cacheFactory, String cacheName, Class<V> valueType)
Create a wrapper around aStableReadExternalCachewith the given name and value type.
-
synchronousStableReadExternalCache
public static <V> SynchronousExternalCache<V> synchronousStableReadExternalCache(com.atlassian.vcache.VCacheFactory cacheFactory, String cacheName, com.atlassian.vcache.Marshaller<V> marshaller, com.atlassian.vcache.ExternalCacheSettingsBuilder cacheSettingsBuilder)
Create a wrapper around aStableReadExternalCachewith the given name, marshaller and cache settings.
-
synchronous
public static <C extends com.atlassian.vcache.ExternalWriteOperationsUnbuffered<V> & com.atlassian.vcache.ExternalCache<V>,V> SynchronousExternalCache<V> synchronous(com.atlassian.util.concurrent.Supplier<C> cacheRef)
Create a wrapper around the given cache supplier.
-
synchronous
public static <C extends com.atlassian.vcache.ExternalWriteOperationsUnbuffered<V> & com.atlassian.vcache.ExternalCache<V>,V> SynchronousExternalCache<V> synchronous(C cache)
Create a wrapper around the given cache.
-
serializableMarshaller
public static <C extends T,T extends Serializable> com.atlassian.vcache.Marshaller<C> serializableMarshaller(Class<T> type)
A utility method for creating a VCache marshaller for the given serializable type, when that type also has a generic signature, e.g. ImmutableList<String>, which otherwise requires unsafe casting. Callers should use this at the own risk, making sure they're using the correct types.
-
remove
public void remove(String key)
Removes a cache entry.- Parameters:
key- the key of the entry to remove- Throws:
SynchronousExternalCache.CacheException- if the remove operation fails
-
remove
public void remove(String key, Consumer<Throwable> onError)
Removes a cache entry.- Parameters:
key- the key of the entry to removeonError- The callback that will be invoked if the remove opertation fails
-
removeAll
public void removeAll()
Remove all entries from the cache- Throws:
SynchronousExternalCache.CacheException- if the remove operation fails
-
put
@Deprecated public boolean put(String key, V value)
Deprecated.since 7.5 Useget(String, Supplier)to populate cache values.Puts an entry into the cache. Will replace any existing entries for the same key.- Parameters:
key- The key of the entryvalue- The value of the entry- Returns:
- whether the entry was put into the cache
- Throws:
SynchronousExternalCache.CacheException- if the put operation fails
-
put
@Deprecated public boolean put(String key, V value, com.atlassian.vcache.PutPolicy putPolicy)
Deprecated.since 7.5 Useget(String, Supplier)to populate cache values.Puts an entry into the cache.- Parameters:
key- The key of the entryvalue- The value of the entryputPolicy- The required policy- Returns:
- whether the entry was put into the cache
- Throws:
SynchronousExternalCache.CacheException- if the put operation fails
-
put
@Deprecated public boolean put(String key, V value, com.atlassian.vcache.PutPolicy putPolicy, Consumer<Throwable> onError)
Deprecated.since 7.5 Useget(String, Supplier)to populate cache values.Puts an entry into the cache.- Parameters:
key- The key of the entryvalue- The value of the entryputPolicy- The required policyonError- The callback to invoked if the operation fails- Returns:
- whether the entry was put into the cache (false if the put operation failed)
-
put
@Deprecated public boolean put(String key, V value, com.atlassian.vcache.PutPolicy putPolicy, Function<Throwable,Boolean> onError)
Deprecated.since 7.5 Useget(String, Supplier)to populate cache values.Puts an entry into the cache.- Parameters:
key- The key of the entryvalue- The value of the entryputPolicy- The required policyonError- The function to invoked if the operation fails- Returns:
- whether the entry was put into the cache, or the result of the errror function if the put operation failed.
-
get
public Optional<V> get(String key)
Get an entry from the cache.- Parameters:
key- the key of the entry- Returns:
- The optional value of the cache entry, or
Optional.empty()if the get operation fails.
-
get
public Optional<V> get(String key, Function<Throwable,Optional<V>> onError)
Get an entry from the cache.- Parameters:
key- the key of the entryonError- The function to be invoked if the get operation fails- Returns:
- The optional value of the cache entry, or the result of the error function if the get operation fails
-
get
public <R> R get(String key, Function<Optional<V>,R> onSuccess, Function<Throwable,R> onError)
Get an entry from the cache.- Parameters:
key- the key of the entryonSuccess- The function to invoked if the get operation succeeds (even if there's no entry for the key)onError- The function to be invoked if the get operation fails- Returns:
- The result of either the success or error functions
-
get
public V get(String key, com.atlassian.util.concurrent.Supplier<V> valueLoader)
Get an entry from the cache.- Parameters:
key- the key of the entryvalueLoader- The supplier of a value for a new cache entry if there is no entry for the key, or if the get operation fails.- Returns:
- Either the value of the existing cache entry, or the result of the loader supplier if no entry was present or if the operation failed.
-
-