Package javax.cache

Interface CacheBuilder<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Known Implementing Classes:
    CacheBuilderImpl

    public interface CacheBuilder<K,​V>
    A CacheBuilder is used for creating Caches. A CacheBuilder is created by CacheManager.createCacheBuilder(String) and is associated with that manager.

    Additional configuration methods may be available on a builder instance by casting to a concrete implementation.

    Since:
    1.0
    Author:
    Yannis Cosmadopoulos
    • Method Detail

      • build

        Cache<K,​V> build()
        Create an instance of the named Cache.

        The Cache will be created, added to the caches controlled by its associated CacheManager and started. If there is an existing Cache of the same name associated with this CacheManager when build is invoked, the old Cache will be stopped.

        Returns:
        a new instance of the named cache
        Throws:
        InvalidConfigurationException - thrown if the configuration is invalid. Examples include if read through has been set to true but no cache loader is specified, or if no cache writer is specified but write through has been set.
        CacheException - if a cache with that name already exists or there was an error adding the cache to the CacheManager
        See Also:
        CacheManager.createCacheBuilder(String)
      • setCacheLoader

        CacheBuilder<K,​V> setCacheLoader​(CacheLoader<K,​? extends V> cacheLoader)
        Sets the cache loader.
        Parameters:
        cacheLoader - the CacheLoader
        Returns:
        the builder
        Throws:
        NullPointerException - if cacheLoader is null.
      • setCacheWriter

        CacheBuilder<K,​V> setCacheWriter​(CacheWriter<? super K,​? super V> cacheWriter)
        Sets the cache writer.
        Parameters:
        cacheWriter - the CacheWriter
        Returns:
        the builder
        Throws:
        NullPointerException - if cacheWriter is null.
      • registerCacheEntryListener

        CacheBuilder<K,​V> registerCacheEntryListener​(CacheEntryListener<K,​V> cacheEntryListener)
        Registers a listener. Can be invoked multiple times.
        Parameters:
        cacheEntryListener - the listener
        Returns:
        the builder
        Throws:
        NullPointerException - if any of the arguments are null.
      • setStatisticsEnabled

        CacheBuilder<K,​V> setStatisticsEnabled​(boolean enableStatistics)
        Sets whether statistics gathering is enabled on this cache.
        Parameters:
        enableStatistics - true to enable statistics, false to disable
        Returns:
        the builder
        See Also:
        CacheConfiguration.setStatisticsEnabled(boolean)
      • setReadThrough

        CacheBuilder<K,​V> setReadThrough​(boolean readThrough)
        Sets whether the cache is a read-through cache. If so a CacheLoader should be configured.
        Parameters:
        readThrough - the value for readThrough
        Returns:
        the builder
      • setWriteThrough

        CacheBuilder<K,​V> setWriteThrough​(boolean writeThrough)
        Whether the cache is a write-through cache. A CacheWriter should be configured.
        Parameters:
        writeThrough - set to true for a write-through cache
        Returns:
        the builder