RuleGo RuleGo
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • 快速入门

  • 规则链

  • 标准组件

    • 标准组件概述
    • 过滤器

    • 动作

    • 转换器

    • 外部的

      • HTTP客户端
      • MQTT客户端
      • 发送邮件
      • 数据库客户端
      • ssh
      • TCP/UDP客户端
      • 缓存设置
      • 缓存获取
      • 缓存删除
        • 配置
          • LevelKey
        • 缓存实现配置
        • Relation Type
        • 执行结果
        • 配置示例
    • 流

  • 扩展组件

  • 自定义组件

  • 组件市场

  • 可视化

  • AOP

  • 触发器

  • 高级主题

  • RuleGo-Server

  • 问题

目录

缓存删除

cacheDelete组件:从缓存中删除指定key的值。缓存实例使用config.Cache 。

# 配置

字段 类型 说明 默认值
keys []LevelKey 缓存键名列表 无

# LevelKey

字段 类型 说明 默认值
level string 缓存级别 chain
key string 键,可以使用组件配置变量 无
  • level: 缓存级别
    • chain: 当前规则链级别缓存,在当前规则链命名空间下操作,用于规则链实例内不同执行上下文之间的数据共享。如果规则链实例被销毁,会自动删除该规则链命名空间下所有缓存。
    • global: 全局级别缓存,在全局命名空间下操作,用于跨规则链间的数据共享
  • key: 缓存键
    • 可以使用 ${metadata.key} 读取元数据中的变量或者使用 ${msg.key} 读取消息负荷中的变量进行替换
    • 支持 * 通配符查找,例如:test:* 表示以test: 开头的所有key

# 缓存实现配置

默认情况下,RuleGo 使用内置的本地内存缓存(utils/cache.MemoryCache),并提供了一个全局默认实例 cache.DefaultCache(默认GC清理周期为5分钟)。如果未通过 types.WithCache 选项指定自定义缓存实现,则系统将自动使用此默认内存缓存。

如需使用其他缓存类型(例如 Redis、Memcached 等),您需要自行实现 types.Cache 接口,并通过 types.WithCache 选项在创建 Config 时将其注入。

types.Cache 接口定义如下:

type Cache interface {  
	// Set 在缓存中存储一个键值对,可选设置过期时间  
	// 参数:  
	//   - key:缓存键(字符串)  
	//   - value:要存储的值(interface{})  
	//   - ttl:存活时间字符串(例如“10m”,“1h”)  
	// 返回:  
	//   - error:如果 ttl 格式无效,则返回错误  
	// 注意:如果 ttl 为 0 或空字符串,则该项永不过期  
	Set(key string, value interface{}, ttl string) error  
	// Get 通过键从缓存中检索值  
	// 参数:  
	//   - key:要查找的缓存键(字符串)  
	// 返回:  
	//   - interface{}:存储的值,如果不存在或已过期则返回 nil  
	Get(key string) interface{}  
	// Has 检查键是否存在于缓存中  
	// 参数:  
	//   - key:要检查的缓存键(字符串)  
	// 返回:  
	//   - bool:如果键存在且未过期,则返回 true,否则返回 false  
	Has(key string) bool  
	// Delete 通过键删除缓存项  
	// 参数:  
	//   - key:要删除的缓存键(字符串)  
	// 返回:  
	//   - error:当前实现始终返回 nil  
	Delete(key string) error  
	// DeleteByPrefix 删除所有具有指定前缀的缓存项  
	// 参数:  
	//   - prefix:要匹配的键前缀(字符串)  
	// 返回:  
	//   - error:当前实现始终返回 nil  
	DeleteByPrefix(prefix string) error  

	// GetByPrefix 检索所有键与指定前缀匹配的值  
	// 参数:  
	//   - prefix:要匹配的键前缀(字符串)  
	// 返回:  
	//   - map[string]interface{}:匹配的键值对映射  
	GetByPrefix(prefix string) map[string]interface{}  
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

配置示例:

// 使用自定义缓存实现
config := rulego.NewConfig(types.WithCache(&myCacheImpl{}))

// 如果使用默认内存的实现,则不需要显式配置,RuleGo会自动使用 cache.DefaultCache
// config := rulego.NewConfig()
1
2
3
4
5

# Relation Type

  • Success: 删除成功,把消息发送到Success链
  • Failure: 删除失败,把消息发送到Failure链

# 执行结果

不改变消息负荷

# 配置示例

{
  "id": "s1",
  "type": "cacheDelete",
  "name": "删除缓存",
  "configuration": {
    "keys": [
      {"level": "chain","key":"${metadata.userId}"},
      {"level": "chain","key":"key1"}
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
在 GitHub 上编辑此页 (opens new window)
上次更新: 2025/05/18, 14:00:38
缓存获取
子规则链

← 缓存获取 子规则链→

Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式