Class 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
    • 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 a StableReadExternalCache with the given name and marshaller.
      • synchronousStableReadExternalCache

        public static <V extends SerializableSynchronousExternalCache<V> synchronousStableReadExternalCache​(com.atlassian.vcache.VCacheFactory cacheFactory,
                                                                                                              String cacheName,
                                                                                                              Class<V> valueType)
        Create a wrapper around a StableReadExternalCache with 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 a StableReadExternalCache with 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,
                           Consumer<Throwable> onError)
        Removes a cache entry.
        Parameters:
        key - the key of the entry to remove
        onError - The callback that will be invoked if the remove opertation fails
      • put

        @Deprecated
        public boolean put​(String key,
                           V value)
        Deprecated.
        since 7.5 Use get(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 entry
        value - 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 Use get(String, Supplier) to populate cache values.
        Puts an entry into the cache.
        Parameters:
        key - The key of the entry
        value - The value of the entry
        putPolicy - 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 Use get(String, Supplier) to populate cache values.
        Puts an entry into the cache.
        Parameters:
        key - The key of the entry
        value - The value of the entry
        putPolicy - The required policy
        onError - 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 Use get(String, Supplier) to populate cache values.
        Puts an entry into the cache.
        Parameters:
        key - The key of the entry
        value - The value of the entry
        putPolicy - The required policy
        onError - 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 entry
        onError - 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 entry
        onSuccess - 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 entry
        valueLoader - 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.