inmem

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("key not found")

Functions

This section is empty.

Types

type Cache

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

Cache is a generic cache implementation with support for time-to-live (TTL) expiration.

func New

func New() *Cache

NewTTL creates a new TTLCache instance and starts a goroutine to periodically remove expired items every 5 seconds.

func (*Cache) Get

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

Get retrieves the value associated with the given key from the cache.

func (*Cache) Keys

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

func (*Cache) Pop

func (c *Cache) Pop(key string) (any, error)

Pop removes and returns the item with the specified key from the cache.

func (*Cache) Remove

func (c *Cache) Remove(keys ...string) error

Remove removes the item with the specified key from the cache.

func (*Cache) Set

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

Set adds a new item to the cache with the specified key, value, and time-to-live (TTL).

Jump to

Keyboard shortcuts

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