plugincache

package
v1.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

README

cache Plugin

This plugin provides a key-value cache backed by the database. Values can be stored with an optional TTL (time-to-live) in seconds. When a TTL is set, the entry is automatically cleaned up on read (lazy expiration) and at service startup (bulk purge). Setting a TTL of 0 (or omitting it) means the entry never expires.

Configuration

Field Description
action set to store a value, get to retrieve a value, or delete to remove a value
key the cache key (required for all actions)
value the value to store (only used with set; can be any JSON-compatible type: string, number, object, array...)
ttl time-to-live in seconds (only used with set; 0 or omitted means no expiration)

Example

Store a value with a 1-hour TTL:

cache-set:
  action:
    type: cache
    configuration:
      action: set
      key: "my-key"
      value:
        foo: bar
        count: 42
      ttl: 3600

Retrieve the value:

cache-get:
  dependencies:
    - cache-set
  action:
    type: cache
    configuration:
      action: get
      key: "my-key"

Delete the value:

cache-delete:
  dependencies:
    - cache-get
  action:
    type: cache
    configuration:
      action: delete
      key: "my-key"

Requirements

None.

Return

set action output
Name Description
key the cache key that was set
cached true if the value was stored
get action output
Name Description
key the cache key that was looked up
hit true if the key was found and not expired, false otherwise
value the cached value (or null if hit is false)
delete action output
Name Description
key the cache key that was deleted
deleted true if the delete was issued

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Init = &CacheInit{}
)
View Source
var (
	Plugin = taskplugin.New("cache", "0.1", exec,
		taskplugin.WithConfig(validConfig, Config{}),
	)
)

Functions

This section is empty.

Types

type CacheInit

type CacheInit struct{}

CacheInit handles the plugin initialization: table registration and periodic cleanup of expired entries.

func (*CacheInit) Description

func (ci *CacheInit) Description() string

func (*CacheInit) Init

func (ci *CacheInit) Init(s *plugins.Service) error

type Config

type Config struct {
	Action string      `json:"action"`
	Key    string      `json:"key"`
	Value  interface{} `json:"value,omitempty"`
	TTL    int64       `json:"ttl,omitempty"`
}

Config holds the configuration for a cache action. Action: "set", "get", or "delete" Key: the cache key (required) Value: the value to store (required for "set", ignored otherwise) TTL: time-to-live in seconds (0 means no expiration, only used with "set")

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL