memory

package
v3.76.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: AGPL-3.0 Imports: 3 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 wraps the go-cache library to provide an in-memory key-value store.

func New

func New(opts ...CacheOption) *Cache

New constructs a new in-memory cache instance with optional configurations. By default, it sets the expiration and purge intervals to 12 and 13 hours, respectively. These defaults can be overridden using the functional options: WithExpirationInterval and WithPurgeInterval.

func NewWithData

func NewWithData(data []CacheEntry, opts ...CacheOption) *Cache

NewWithData constructs a new in-memory cache with existing data. It also accepts CacheOption parameters to override default configuration values.

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all key-value pairs from the cache.

func (*Cache) Contents

func (c *Cache) Contents() string

Contents returns a comma-separated string containing all keys in the cache.

func (*Cache) Count

func (c *Cache) Count() int

Count returns the number of key-value pairs in the cache.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes the key-value pair from the cache.

func (*Cache) Exists

func (c *Cache) Exists(key string) bool

Exists returns true if the given key exists in the cache.

func (*Cache) Get

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

Get returns the value for the given key.

func (*Cache) Keys added in v3.34.0

func (c *Cache) Keys() []string

Keys returns all keys in the cache.

func (*Cache) Set

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

Set adds a key-value pair to the cache.

func (*Cache) Values added in v3.34.0

func (c *Cache) Values() []any

Values returns all values in the cache.

type CacheEntry added in v3.63.9

type CacheEntry struct {
	// Key is the unique identifier for the entry.
	Key string
	// Value is the data stored in the entry.
	Value any
}

CacheEntry represents a single entry in the cache, consisting of a key and its corresponding value.

type CacheOption added in v3.63.9

type CacheOption func(*Cache)

CacheOption defines a function type used for configuring a Cache.

func WithExpirationInterval added in v3.63.9

func WithExpirationInterval(interval time.Duration) CacheOption

WithExpirationInterval returns a CacheOption to set the expiration interval of cache items. The interval determines the duration a cached item remains in the cache before it is expired.

func WithPurgeInterval added in v3.63.9

func WithPurgeInterval(interval time.Duration) CacheOption

WithPurgeInterval returns a CacheOption to set the interval at which the cache purges expired items. Regular purging helps in freeing up memory by removing stale entries.

Jump to

Keyboard shortcuts

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