Class CacheProperties

java.lang.Object
cloud.opencode.base.cache.spring.CacheProperties

public class CacheProperties extends Object
Cache Properties - Configuration properties for cache auto-configuration 缓存属性 - 缓存自动配置的配置属性

Properties can be configured in application.yml or application.properties:

属性可以在 application.yml 或 application.properties 中配置:

# application.yml
opencode:
  cache:
    enabled: true
    allow-null-values: true
    default:
      maximum-size: 10000
      expire-after-write: 30m
      expire-after-access: 10m
      record-stats: true
    caches:
      users:
        maximum-size: 5000
        expire-after-write: 1h
      products:
        maximum-size: 50000
        expire-after-write: 24h

Features | 主要功能:

  • Default cache configuration - 默认缓存配置
  • Per-cache named configuration - 每缓存命名配置
  • Spring property binding compatible - Spring 属性绑定兼容
  • Null-value caching option - 空值缓存选项

Usage Examples | 使用示例:

CacheProperties props = new CacheProperties();
props.setEnabled(true);
props.getDefaults().setMaximumSize(10000L);

Security | 安全性:

  • Thread-safe: No (mutable configuration bean) - 线程安全: 否(可变配置 Bean)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-cache V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Field Details

  • Constructor Details

    • CacheProperties

      public CacheProperties()
      Creates a new CacheProperties with defaults | 使用默认值创建新的缓存属性
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Returns whether cache is enabled | 返回缓存是否启用
      Returns:
      true if enabled | 启用返回 true
    • setEnabled

      public void setEnabled(boolean enabled)
      Sets whether cache is enabled | 设置缓存是否启用
      Parameters:
      enabled - true to enable | true 为启用
    • isAllowNullValues

      public boolean isAllowNullValues()
      Returns whether null values are allowed | 返回是否允许空值
      Returns:
      true if allowed | 允许返回 true
    • setAllowNullValues

      public void setAllowNullValues(boolean allowNullValues)
      Sets whether null values are allowed | 设置是否允许空值
      Parameters:
      allowNullValues - true to allow | true 为允许
    • getDefaultSpec

      public CacheProperties.CacheSpec getDefaultSpec()
      Returns the default cache spec | 返回默认缓存规格
      Returns:
      default spec | 默认规格
    • setDefaultSpec

      public void setDefaultSpec(CacheProperties.CacheSpec defaultSpec)
      Sets the default cache spec | 设置默认缓存规格
      Parameters:
      defaultSpec - the default spec | 默认规格
    • getCaches

      public Map<String, CacheProperties.CacheSpec> getCaches()
      Returns the named cache configurations | 返回命名缓存配置
      Returns:
      cache configurations | 缓存配置
    • setCaches

      public void setCaches(Map<String, CacheProperties.CacheSpec> caches)
      Sets the named cache configurations | 设置命名缓存配置
      Parameters:
      caches - cache configurations | 缓存配置
    • addCache

      public CacheProperties addCache(String name, CacheProperties.CacheSpec spec)
      Add a named cache configuration 添加命名缓存配置
      Parameters:
      name - the cache name | 缓存名称
      spec - the cache specification | 缓存规格
      Returns:
      this for chaining | 返回 this 以支持链式调用
    • removeCache

      public CacheProperties removeCache(String name)
      Remove a named cache configuration 删除命名缓存配置
      Parameters:
      name - the cache name | 缓存名称
      Returns:
      this for chaining | 返回 this 以支持链式调用
    • clearCaches

      public CacheProperties clearCaches()
      Clear all named cache configurations 清除所有命名缓存配置
      Returns:
      this for chaining | 返回 this 以支持链式调用
    • validate

      public void validate()
      Validate all cache configurations 验证所有缓存配置
      Throws:
      IllegalArgumentException - if any configuration is invalid | 如果任何配置无效抛出异常
      Since:
      V2.0.1