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
        • Configuration
          • CacheItem
        • Cache Implementation Configuration
        • Relation Type
        • Execution Result
        • Configuration Example
      • Cache Get
      • Cache Delete
    • flow

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • RuleGo-Server

  • FAQ

  • Endpoint Module

  • Support

  • StreamSQL

目录

Cache Set

cacheSet component: Sets the value of a specified key in the cache. The cache instance uses config.Cache.

# Configuration

Field Type Description Default Value
items []CacheItem List of cache items, can use component configuration variables None
  • level: Cache level
    • chain: Cache at the current rule chain level, operating within the current rule chain namespace, used for data sharing between different execution contexts within the rule chain instance.If the rule chain instance is destroyed, all caches under the rule chain namespace will be automatically deleted.
    • global: Global-level cache, operating within the global namespace, used for data sharing across rule chains.

# CacheItem

Field Type Description Default Value
level string Cache level chain
key string Key, can use component configuration variables None
value any Value, can use component configuration variables None
ttl string Expiration time, examples: 1h (1 hour), 1h30m (1 hour 30 minutes), 10m (10 minutes), 10s (10 seconds). If empty or 0, it means never expires. None

# 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 setting is successful, the message is sent to the Success chain.
  • Failure: If the setting fails, the message is sent to the Failure chain.

# Execution Result

The message payload remains unchanged.

# Configuration Example

{
  "id": "s1",
  "type": "cacheSet",
  "name": "Set Cache",
  "configuration": {
    "items": [
      {
        "level": "chain",
        "key": "testKey",
        "value": "testValue",
        "ttl": ""
      }
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Edit this page on GitHub (opens new window)
Last Updated: 2026/01/29, 01:34:57
net
Cache Get

← net Cache Get→

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

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