cache

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

func New

func New(cfg Config, logger *zap.Logger) (*Cache, error)

New creates a new cache instance

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all entries from the cache

func (*Cache) Close

func (c *Cache) Close()

Close shuts down the cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes a value from the cache

func (*Cache) Get

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

Get retrieves a value from the cache

func (*Cache) Metrics

func (c *Cache) Metrics() *ristretto.Metrics

Metrics returns cache performance metrics

func (*Cache) Set

func (c *Cache) Set(key string, value any, ttl time.Duration)

Set stores a value in the cache with TTL

type Config

type Config struct {
	// MaxCost is the maximum cost of cache entries (in bytes approximately)
	MaxCost int64
	// NumCounters is the number of keys to track frequency
	NumCounters int64
	// BufferItems is the size of the internal buffer
	BufferItems int64
}

Config holds cache configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the cache

Jump to

Keyboard shortcuts

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