RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

    • Standard Components Overview
    • common

    • filter

    • action

    • transform

    • external

      • restApiCall
      • mqttClient
      • sendEmail
      • dbClient
      • ssh
      • net
      • Cache Set
      • Cache Get
        • Configuration
          • LevelKey
        • Cache Implementation Configuration
        • Relation Type
        • Execution Result
        • Configuration Example
      • Cache Delete
    • flow

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • RuleGo-Server

  • FAQ

  • Endpoint Module

  • Support

  • StreamSQL

目录

Cache Get

cacheGet component: Retrieves the values of a specified list of keys from the cache. The cache instance uses config.Cache.

# Configuration

Field Type Description Default Value
keys []LevelKey List of cache keys None
outputMode int Output mode 2
  • outputMode: Output mode
    • 0: Merge the query results into the current message metadata.
    • 1: Merge into the current message payload. Requires that the input message payload DataType must be of JSON type and that the message payload Data can be parsed as a map structure.
    • 2: Convert the query results to JSON and overwrite the original message payload for output.

# LevelKey

Field Type Description Default Value
level string Cache level chain
key string Key, which can use component configuration variables None
  • level: Cache level
    • chain: Cache at the current rule chain level, operating within the current rule chain namespace. It is used for data sharing between different execution contexts within the same rule chain instance. If the rule chain instance is destroyed, all caches under this rule chain namespace will be automatically deleted.
    • global: Cache at the global level, operating within the global namespace. It is used for data sharing across different rule chains.
  • key: Cache key
    • You can use ${metadata.key} to read variables from metadata or ${msg.key} to read variables from the message payload for replacement.
    • Supports wildcard character * for pattern matching. For example, test:* represents all keys starting with test:.

# Cache Implementation Configuration

By default, RuleGo uses the built-in local memory cache (utils/cache.MemoryCache) and provides a global default instance cache.DefaultCache (with a default GC cleanup cycle of 5 minutes). If no custom cache implementation is specified via the types.WithCache option, the system will automatically use this default memory cache.

To use other cache types (such as Redis, Memcached, etc.), you need to implement the types.Cache interface yourself and inject it via the types.WithCache option when creating the Config.

The types.Cache interface is defined as follows:

type Cache interface {  
	// Set stores a key-value pair in the cache with optional expiration time.
	// Parameters:
	//   - key: Cache key (string)
	//   - value: Value to store (interface{})
	//   - ttl: Time-to-live duration string (e.g., "10m", "1h")
	// Returns:
	//   - error: Returns an error if the ttl format is invalid.
	// Note: If ttl is 0 or an empty string, the item never expires.
	Set(key string, value interface{}, ttl string) error  
	// Get retrieves a value from the cache by key.
	// Parameters:
	//   - key: Cache key to look up (string)
	// Returns:
	//   - interface{}: Stored value
	//   - error: Returns an error if it does not exist or has expired.
	Get(key string) (interface{}, error)  
	// Has checks if a key exists in the cache.
	// Parameters:
	//   - key: Cache key to check (string)
	// Returns:
	//   - bool: Returns true if the key exists and has not expired, otherwise false.
	Has(key string) bool  
	// Delete removes a cache item by key.
	// Parameters:
	//   - key: Cache key to delete (string)
	// Returns:
	//   - error: Current implementation always returns nil.
	Delete(key string) error  
	// DeleteByPrefix deletes all cache items with the specified prefix.
	// Parameters:
	//   - prefix: Key prefix to match (string)
	// Returns:
	//   - error: Current implementation always returns nil.
	DeleteByPrefix(prefix string) error  

	// GetByPrefix retrieves all values with keys matching the specified prefix.
	// Parameters:
	//   - prefix: Key prefix to match (string)
	// Returns:
	//   - map[string]interface{}: Map of matching key-value pairs.
	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
43

Configuration example:

// Using a custom cache implementation
config := rulego.NewConfig(types.WithCache(&myCacheImpl{}))

// If using the default in-memory implementation, no explicit configuration is needed. RuleGo will automatically use cache.DefaultCache.
// config := rulego.NewConfig()
1
2
3
4
5

# Relation Type

  • Success: If the retrieval is successful, the message is sent to the Success chain.
  • Failure: If the retrieval fails or the cache is not found when outputMode=2, the message is sent to the Failure chain.

# Execution Result

The query results are merged according to the outputMode parameter, and the message is sent to the Success chain.

  • outputMode: Output mode
    • 0: Merge the query results into the current message metadata.
    • 1: Merge into the current message payload. Requires that the input message payload DataType must be of JSON type and that the message payload Data can be parsed as a map structure.
    • 2: Convert the query results to JSON and overwrite the original message payload for output.

# Configuration Example

{
  "id": "s1",
  "type": "cacheGet",
  "name": "Get Cache",
  "configuration": {
    "keys": [
      {"level": "chain","key":"${metadata.userId}"}, 
      {"level": "chain","key":"key1"}
    ],
    "outputMode": 2
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
Edit this page on GitHub (opens new window)
Last Updated: 2026/01/29, 01:34:57
Cache Set
Cache Delete

← Cache Set Cache Delete→

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

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