cache

package module
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigKey = "cache"

ConfigKey is the configuration key under which cache settings are stored.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides a high-performance in-memory cache backed by Otter.

func (*Cache) ComputeIfAbsent

func (c *Cache) ComputeIfAbsent(key string, f func() (any, bool)) (any, bool)

ComputeIfAbsent atomically computes a value if the key is not present. f should return (value, cancel); if cancel is true the operation is aborted.

func (*Cache) Get

func (c *Cache) Get(key string) (any, bool)

Get returns the cached value for the given key, or (nil, false) if not found.

func (*Cache) GetOrSet

func (c *Cache) GetOrSet(key string, f func() any) any

GetOrSet returns the cached value or computes and stores it using f.

func (*Cache) Init

func (c *Cache) Init(context *core.Context) error

func (*Cache) Invalidate

func (c *Cache) Invalidate(key string) (any, bool)

Invalidate removes a key from the cache.

func (*Cache) Set

func (c *Cache) Set(key string, value any)

Set stores a value in the cache.

func (*Cache) SetIfAbsent

func (c *Cache) SetIfAbsent(key string, value any) (any, bool)

SetIfAbsent stores a value only if the key does not already exist.

func (*Cache) SetNX

func (c *Cache) SetNX(key string, value any, expire time.Duration) (any, bool)

SetNX stores a value with an expiration if the key does not already exist. Returns (value, true) on success, or (existing, false) if the key exists.

func (*Cache) Stats

func (c *Cache) Stats() stats.Stats

Stats returns cache performance statistics.

type Config

type Config struct {
	MaxSize int // Maximum number of cached entries
	Expiry  int // Cache TTL in seconds
}

Config holds cache configuration settings.

Jump to

Keyboard shortcuts

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