Class FlagsmithCacheConfig.Builder

java.lang.Object
com.flagsmith.config.FlagsmithCacheConfig.Builder
Enclosing class:
FlagsmithCacheConfig

public static class FlagsmithCacheConfig.Builder
extends Object
  • Method Details

    • expireAfterWrite

      public FlagsmithCacheConfig.Builder expireAfterWrite​(int duration, TimeUnit timeUnit)
      Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, or the most recent replacement of its value.
      Parameters:
      duration - an integer matching the time unit.
      timeUnit - minutes, seconds, etc.
      Returns:
      the Builder
    • expireAfterAccess

      public FlagsmithCacheConfig.Builder expireAfterAccess​(int duration, TimeUnit timeUnit)
      Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.
      Parameters:
      duration - an integer matching the time unit.
      timeUnit - minutes, seconds, etc.
      Returns:
      the Builder
    • maxSize

      public FlagsmithCacheConfig.Builder maxSize​(int maxSize)
      Specifies the maximum number of entries the cache may contain. Note that the cache may evict an entry before this limit is exceeded or temporarily exceed the threshold while evicting.

      As the cache size grows close to the maximum, the cache evicts entries that are less likely to be used again.

      For example, the cache may evict an entry because it hasn't been used recently or very often.

      Parameters:
      maxSize - size. When size is zero, elements will be evicted immediately after being loaded into the cache. This can be useful in testing, or to disable caching temporarily without a code change.
      Returns:
      the Builder
    • recordStats

      public FlagsmithCacheConfig.Builder recordStats()
      Enables the accumulation of CacheStats during the operation of the cache.

      Without this Cache.stats() will return zero for all statistics. Note that recording statistics requires bookkeeping to be performed with each operation, and thus imposes a performance penalty on cache operation.

      Returns:
      the Builder
    • enableEnvLevelCaching

      public FlagsmithCacheConfig.Builder enableEnvLevelCaching​(String envFlagsCacheKey)
      Enables caching for environment level flags.

      Flags for users are stored in the cache using the user-identifier as the cache key.

      For environment level flags, you need to configure a key with the builder to enable caching environment flags.

      This is required to ensure the programmer chooses an environment-level-key that does not conflict with user identifiers.

      IMPORTANT: make sure you set an environment key that will never match a user identifier.

      Otherwise, the cache will not be able to distinguish between the 2.

      Parameters:
      envFlagsCacheKey - key to use in the cache for environment level flags
      Returns:
      the Builder
    • build

      public FlagsmithCacheConfig build()