Class ConfigurationProvider


  • public final class ConfigurationProvider
    extends Object
    Utility class for common configuration handling patterns. This class provides static methods for creating common configuration objects and handling default values, eliminating duplication across cache implementations.
    • Method Detail

      • createBasicConfig

        public static <K,​V> CacheConfig<K,​V> createBasicConfig​(long maximumSize,
                                                                           boolean recordStats)
        Creates a basic configuration object with minimal settings. Used by many cache implementations for their config() method.
        Parameters:
        maximumSize - the maximum size
        recordStats - whether to record statistics
        Returns:
        a basic cache configuration
      • createSizeWeightConfig

        public static <K,​V> CacheConfig<K,​V> createSizeWeightConfig​(long maximumSize,
                                                                                long maximumWeight,
                                                                                boolean recordStats)
        Creates a configuration object with size and weight limits.
        Parameters:
        maximumSize - the maximum size
        maximumWeight - the maximum weight
        recordStats - whether to record statistics
        Returns:
        a cache configuration with size and weight limits
      • calculateOptimalCapacity

        public static int calculateOptimalCapacity​(long maximumSize)
        Calculates the optimal initial capacity for a ConcurrentHashMap based on the maximum size and load factor.
        Parameters:
        maximumSize - the maximum expected size
        Returns:
        the optimal initial capacity
      • calculateOptimalConcurrency

        public static int calculateOptimalConcurrency()
        Calculates the optimal concurrency level for concurrent data structures.
        Returns:
        the optimal concurrency level
      • validateConfiguration

        public static void validateConfiguration​(CacheConfig<?,​?> config)
        Validates cache configuration parameters and throws appropriate exceptions.
        Parameters:
        config - the configuration to validate
        Throws:
        IllegalArgumentException - if configuration is invalid
      • getSafeMaximumSize

        public static long getSafeMaximumSize​(CacheConfig<?,​?> config)
        Gets a safe maximum size value, handling null cases.
        Parameters:
        config - the cache configuration
        Returns:
        the maximum size or Long.MAX_VALUE if not specified
      • getSafeInitialCapacity

        public static int getSafeInitialCapacity​(CacheConfig<?,​?> config)
        Gets a safe initial capacity value, handling null cases.
        Parameters:
        config - the cache configuration
        Returns:
        the initial capacity or a calculated default
      • hasExpiration

        public static boolean hasExpiration​(CacheConfig<?,​?> config)
        Checks if the configuration has expiration settings.
        Parameters:
        config - the cache configuration
        Returns:
        true if any expiration is configured
      • hasRefresh

        public static boolean hasRefresh​(CacheConfig<?,​?> config)
        Checks if the configuration has refresh settings.
        Parameters:
        config - the cache configuration
        Returns:
        true if refresh is configured
      • hasLoader

        public static boolean hasLoader​(CacheConfig<?,​?> config)
        Checks if the configuration has loading capability.
        Parameters:
        config - the cache configuration
        Returns:
        true if loader or async loader is configured