cache

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cache implements a thread-safe LRU cache with size-based eviction.

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 is a thread-safe LRU cache that evicts the least recently used entries when the total size exceeds the configured maximum.

func New

func New(maxSizeB int) *Cache

New creates a new LRU cache with the given maximum size in bytes.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes the entry for the given key from the cache.

func (*Cache) Get

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

Get returns the value for the given key, moving it to the front of the LRU list.

func (*Cache) Set

func (c *Cache) Set(key string, val Value)

Set stores a value in the cache for the given key, evicting old entries if necessary.

func (*Cache) SizeB

func (c *Cache) SizeB() int

SizeB returns the current total size of the cache in bytes.

func (*Cache) Update

func (c *Cache) Update(key string, fn func(v Value) Value)

Update updates the given cache value while locked. If the key is not present, nil is passed to fn. To remove the value, return nil in fn.

type Value

type Value interface {
	SizeB() int
}

Value is an interface for cache entries that report their size in bytes.

Jump to

Keyboard shortcuts

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