taolib.testing.config_center.cache.config_cache#

配置缓存策略模块。

提供 Redis 缓存实现和内存缓存实现(用于测试)。

Attributes#

Classes#

ConfigCacheProtocol

配置缓存协议。

RedisConfigCache

Redis 配置缓存实现。

InMemoryConfigCache

内存配置缓存实现(用于测试)。

Module Contents#

taolib.testing.config_center.cache.config_cache.logger#
class taolib.testing.config_center.cache.config_cache.ConfigCacheProtocol#

Bases: Protocol

配置缓存协议。

async get(environment: str, service: str, key: str) Any | None#

获取配置缓存。

参数:
  • environment -- 环境类型

  • service -- 服务名称

  • key -- 配置键

返回:

缓存的配置值,如果不存在则返回 None

async set(environment: str, service: str, key: str, value: Any, ttl: int = 300) None#

设置配置缓存。

参数:
  • environment -- 环境类型

  • service -- 服务名称

  • key -- 配置键

  • value -- 配置值

  • ttl -- 过期时间(秒)

async delete(environment: str, service: str, key: str) None#

删除配置缓存。

参数:
  • environment -- 环境类型

  • service -- 服务名称

  • key -- 配置键

async delete_pattern(environment: str | None = None, service: str | None = None) None#

批量删除配置缓存。

参数:
  • environment -- 环境类型(可选)

  • service -- 服务名称(可选)

class taolib.testing.config_center.cache.config_cache.RedisConfigCache(redis_client: redis.asyncio.Redis)#

Redis 配置缓存实现。

_redis#
async get(environment: str, service: str, key: str) Any | None#

获取配置缓存。

async set(environment: str, service: str, key: str, value: Any, ttl: int = 300) None#

设置配置缓存。

async delete(environment: str, service: str, key: str) None#

删除配置缓存。

async delete_pattern(environment: str | None = None, service: str | None = None) None#

批量删除配置缓存。

class taolib.testing.config_center.cache.config_cache.InMemoryConfigCache#

内存配置缓存实现(用于测试)。

_cache: dict[str, tuple[Any, float]]#
async get(environment: str, service: str, key: str) Any | None#

获取配置缓存。

async set(environment: str, service: str, key: str, value: Any, ttl: int = 300) None#

设置配置缓存。

async delete(environment: str, service: str, key: str) None#

删除配置缓存。

async delete_pattern(environment: str | None = None, service: str | None = None) None#

批量删除配置缓存。