Cache Delete
cacheDelete component: Deletes the value of a specified key from the cache.
The cache instance uses config.Cache.
# Configuration
| Field | Type | Description | Default Value |
|---|---|---|---|
| keys | []LevelKey | List of cache keys | None |
# 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 withtest:.
- You can use
# 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
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
2
3
4
5
# Relation Type
- Success: If the deletion is successful, the message is sent to the
Successchain. - Failure: If the deletion fails, the message is sent to the
Failurechain.
# Execution Result
The message payload remains unchanged.
# Configuration Example
{
"id": "s1",
"type": "cacheDelete",
"name": "Delete Cache",
"configuration": {
"keys": [
{"level": "chain","key":"${metadata.userId}"},
{"level": "chain","key":"key1"}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Edit this page on GitHub (opens new window)
Last Updated: 2026/01/29, 01:34:57