Class JCacheXDistributedCacheFactory


  • public class JCacheXDistributedCacheFactory
    extends Object
    Factory for creating distributed caches with Spring configuration integration.

    This factory allows programmatic creation of distributed caches while respecting the global configuration defaults defined in JCacheXProperties. It provides seamless scaling from local to distributed caching.

    Key Features:

    • Configuration Integration: Respects global distributed properties
    • Cluster Management: Automatic cluster formation and node discovery
    • Consistency Control: Configurable consistency levels per cache
    • Replication Management: Configurable replication factors
    • Spring Compatible: Works seamlessly with Spring's dependency injection

    Usage Examples:

     {
         @code
         @Service
         public class CacheService {
    
    Since:
    1.0.0
    See Also:
    JCacheXProperties, JCacheXDistributedCacheManager, DistributedCache
    • Constructor Detail

      • JCacheXDistributedCacheFactory

        public JCacheXDistributedCacheFactory​(JCacheXProperties properties)
        Creates a new distributed cache factory with the specified properties.
        Parameters:
        properties - the JCacheX configuration properties
    • Method Detail

      • createDistributedCache

        public <K,​V> io.github.dhruv1110.jcachex.distributed.DistributedCache<K,​V> createDistributedCache​(String cacheName)
        Creates a distributed cache with the specified name using default configuration.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        cacheName - the name of the cache
        Returns:
        the created distributed cache instance
      • createDistributedCache

        public <K,​V> io.github.dhruv1110.jcachex.distributed.DistributedCache<K,​V> createDistributedCache​(String cacheName,
                                                                                                                      JCacheXDistributedCacheFactory.DistributedCacheConfigurator<K,​V> configurator)
        Creates a distributed cache with the specified name and custom configuration.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        cacheName - the name of the cache
        configurator - function to customize the cache configuration
        Returns:
        the created distributed cache instance
      • createDistributedCache

        public <K,​V> io.github.dhruv1110.jcachex.distributed.DistributedCache<K,​V> createDistributedCache​(String cacheName,
                                                                                                                      Class<K> keyType,
                                                                                                                      Class<V> valueType,
                                                                                                                      JCacheXDistributedCacheFactory.DistributedCacheConfigurator<K,​V> configurator)
        Creates a distributed cache with the specified name, types, and custom configuration.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        cacheName - the name of the cache
        keyType - the key type class
        valueType - the value type class
        configurator - function to customize the cache configuration
        Returns:
        the created distributed cache instance
      • getDistributedCache

        public <K,​V> io.github.dhruv1110.jcachex.distributed.DistributedCache<K,​V> getDistributedCache​(String cacheName)
        Gets an existing distributed cache by name.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        cacheName - the name of the cache
        Returns:
        the cache instance, or null if not found
      • hasDistributedCache

        public boolean hasDistributedCache​(String cacheName)
        Checks if a distributed cache with the specified name exists.
        Parameters:
        cacheName - the cache name
        Returns:
        true if the cache exists
      • removeDistributedCache

        public <K,​V> io.github.dhruv1110.jcachex.distributed.DistributedCache<K,​V> removeDistributedCache​(String cacheName)
        Removes a distributed cache from the registry.
        Parameters:
        cacheName - the cache name
        Returns:
        the removed cache, or null if not found
      • getCacheNames

        public Set<String> getCacheNames()
        Gets all registered distributed cache names.
        Returns:
        set of cache names