memory

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 7 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DriverName             = "memory" // Name of the memory cache driver
	DefaultSize            = 1024
	DefaultCapacity        = 1024
	DefaultExpiration      = 0
	DefaultCleanupInterval = 300
)

Variables

View Source
var (
	ErrKeyNotFound           = errors.New("key not found")
	ErrCacheSizeLimitReached = errors.New("cache size limit reached")
)

Functions

func New added in v0.2.13

Types

type Cache

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

Cache is an in-memory cache implementation.

func (*Cache) Clear

func (c *Cache) Clear(ctx context.Context) error

Clear clears the cache.

func (*Cache) Close

func (c *Cache) Close(ctx context.Context) error

Close closes the cache.

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

Delete deletes the value associated with the given key.

func (*Cache) Exists

func (c *Cache) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a value exists for the given key.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) (string, error)

Get retrieves the value associated with the given key.

func (*Cache) GetAndDelete

func (c *Cache) GetAndDelete(ctx context.Context, key string) (string, error)

GetAndDelete retrieves the value associated with the given key and deletes it.

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, key string, value string, exp ...time.Duration) error

Set sets the value for the given key.

type Item added in v0.2.13

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

Item represents an item stored in the cache.

Jump to

Keyboard shortcuts

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