Interface ICacheService

  • All Known Implementing Classes:
    HashMapCacheService, HazelcastCacheService, JcsCacheService

    public interface ICacheService
    The cache service interface which enables the cache service loader to instantiate any service no matter the implementation. All services should be able to provide a cache and methods to interact with it.
    • Method Detail

      • initialise

        void initialise​(Properties properties)
        Initialise the cache service based on the supplied Properties object.
        Parameters:
        properties - the Properties object to apply to the cache service
      • shutdown

        void shutdown()
        Shutdown the cache service.
      • getCache

        <K,​V> ICache<K,​V> getCache​(String cacheName)
        Get the named cache from the cache service.
        Type Parameters:
        K - The object type that acts as the key for the cache
        V - The value that is stored in the cache
        Parameters:
        cacheName - the name of the cache to retrieve
        Returns:
        the requested cache object
      • getFromCache

        default <K,​V> V getFromCache​(String cacheName,
                                           K key)
                                    throws CacheOperationException
        Get the value associated with the specified cache and key.
        Type Parameters:
        K - The object type that acts as the key for the cache
        V - The value that is stored in the cache
        Parameters:
        cacheName - the name of the cache to look in
        key - the key of the entry to lookup
        Returns:
        the requested cache object
        Throws:
        CacheOperationException - if issue getting from cache.
      • putInCache

        default <K,​V> void putInCache​(String cacheName,
                                            K key,
                                            V value)
                                     throws CacheOperationException
        Add a new key-value pair to the specified cache.
        Type Parameters:
        K - The object type that acts as the key for the cache
        V - The value that is stored in the cache
        Parameters:
        cacheName - the name of the cache
        key - the key to add
        value - the value to add
        Throws:
        CacheOperationException - if issue adding to cache.
      • putSafeInCache

        default <K,​V> void putSafeInCache​(String cacheName,
                                                K key,
                                                V value)
                                         throws CacheOperationException
        Add a new key-value pair to the specified cache, but only if there is no existing entry associated with the specified key.
        Type Parameters:
        K - The object type that acts as the key for the cache
        V - The value that is stored in the cache
        Parameters:
        cacheName - the name of the cache
        key - the key to add
        value - the value to add
        Throws:
        CacheOperationException - if issue adding to cache.
      • removeFromCache

        default <K> void removeFromCache​(String cacheName,
                                         K key)
        Remove the entry associated with the specified key from the specified cache.
        Type Parameters:
        K - The object type that acts as the key for the cache
        Parameters:
        cacheName - the name of the cache to look in
        key - the key of the entry to remove
      • getAllValuesFromCache

        default <K,​V> Iterable<V> getAllValuesFromCache​(String cacheName)
        Get all of the values associated with the specified cache.
        Type Parameters:
        K - The object type that acts as the key for the cache
        V - The value that is stored in the cache
        Parameters:
        cacheName - the name of the cache to look in
        Returns:
        the requested cache objects
      • getAllKeysFromCache

        default <K,​V> Iterable<K> getAllKeysFromCache​(String cacheName)
        Get all of the keys associated with the specified cache.
        Type Parameters:
        K - The object type that acts as the key for the cache
        V - The value that is stored in the cache
        Parameters:
        cacheName - the name of the cache to look in
        Returns:
        the requested cache keys
      • sizeOfCache

        default int sizeOfCache​(String cacheName)
        Retrieve the size of the specified cache.
        Parameters:
        cacheName - the name of the cache
        Returns:
        the size of the cache
      • clearCache

        default void clearCache​(String cacheName)
                         throws CacheOperationException
        Clear the contents of the specified cache.
        Parameters:
        cacheName - the name of the cache to clear
        Throws:
        CacheOperationException - if there was an error clearing the cache