fifocache

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShardInt

func ShardInt[T constraints.Integer](v T) uint64

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache implements an in-memory cache with FIFO-based eviction

func New

func New[K comparable, V any](
	capacity fscache.CapacityFunc,
	keyShardFunc func(K) uint64,
	postSet func(ctx context.Context, key K, value V, size int64, seq uint64),
	postGet func(ctx context.Context, key K, value V, size int64),
	postEvict func(ctx context.Context, key K, value V, size int64, seq uint64),
) *Cache[K, V]

func NewWithPrepareSet

func NewWithPrepareSet[K comparable, V any](
	capacity fscache.CapacityFunc,
	keyShardFunc func(K) uint64,
	prepareSet func(ctx context.Context, key K, value V, size int64, seq uint64) func(inserted bool),
	postSet func(ctx context.Context, key K, value V, size int64, seq uint64),
	postGet func(ctx context.Context, key K, value V, size int64),
	postEvict func(ctx context.Context, key K, value V, size int64, seq uint64),
) *Cache[K, V]

func (*Cache[K, V]) Capacity

func (c *Cache[K, V]) Capacity() int64

func (*Cache[K, V]) Contains

func (c *Cache[K, V]) Contains(key K) bool

func (*Cache[K, V]) CurrentSeq

func (c *Cache[K, V]) CurrentSeq(key K) (uint64, bool)

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(ctx context.Context, key K)

func (*Cache[K, V]) Evict added in v1.2.3

func (c *Cache[K, V]) Evict(ctx context.Context, done chan int64, capacityCut int64)

func (*Cache[K, V]) EvictToTargetWithWait

func (c *Cache[K, V]) EvictToTargetWithWait(ctx context.Context, target int64) int64

func (*Cache[K, V]) EvictWithWait

func (c *Cache[K, V]) EvictWithWait(ctx context.Context, capacityCut int64) int64

EvictWithWait is like Evict but blocks until the eviction lock is acquired, guaranteeing that eviction actually runs before returning. This is used by EnsureNBytes to prevent unbounded memory growth under high concurrency where TryLock-based Evict would skip eviction entirely. It returns actual used bytes after eviction stops.

func (*Cache[K, V]) ForceEvict

func (c *Cache[K, V]) ForceEvict(ctx context.Context, n int64)

ForceEvict evicts n bytes despite capacity

func (*Cache[K, V]) ForceEvictWithWait

func (c *Cache[K, V]) ForceEvictWithWait(ctx context.Context, n int64) int64

ForceEvictWithWait evicts n bytes despite capacity and waits for callbacks.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(ctx context.Context, key K) (value V, ok bool)

func (*Cache[K, V]) Replace

func (c *Cache[K, V]) Replace(ctx context.Context, key K, value V, size int64) bool

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(ctx context.Context, key K, value V, size int64) (inserted bool, rejected bool)

func (*Cache[K, V]) SetAdmissionTarget

func (c *Cache[K, V]) SetAdmissionTarget(admissionTarget func(capacity int64) (int64, bool))

func (*Cache[K, V]) Used

func (c *Cache[K, V]) Used() int64

type DataCache added in v1.2.3

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

func NewDataCache added in v1.2.3

func NewDataCache(
	capacity fscache.CapacityFunc,
	postSet func(ctx context.Context, key fscache.CacheKey, value fscache.Data, size int64, seq uint64),
	postGet func(ctx context.Context, key fscache.CacheKey, value fscache.Data, size int64),
	postEvict func(ctx context.Context, key fscache.CacheKey, value fscache.Data, size int64, seq uint64),
) *DataCache

func NewDataCacheWithPrepareSet

func NewDataCacheWithPrepareSet(
	capacity fscache.CapacityFunc,
	prepareSet func(ctx context.Context, key fscache.CacheKey, value fscache.Data, size int64, seq uint64) func(inserted bool),
	postSet func(ctx context.Context, key fscache.CacheKey, value fscache.Data, size int64, seq uint64),
	postGet func(ctx context.Context, key fscache.CacheKey, value fscache.Data, size int64),
	postEvict func(ctx context.Context, key fscache.CacheKey, value fscache.Data, size int64, seq uint64),
) *DataCache

func (*DataCache) Available added in v1.2.3

func (d *DataCache) Available() int64

func (*DataCache) Capacity added in v1.2.3

func (d *DataCache) Capacity() int64

func (*DataCache) Contains

func (d *DataCache) Contains(key query.CacheKey) bool

func (*DataCache) CurrentSeq

func (d *DataCache) CurrentSeq(key query.CacheKey) (uint64, bool)

func (*DataCache) DeletePaths added in v1.2.3

func (d *DataCache) DeletePaths(ctx context.Context, paths []string)

func (*DataCache) EnsureNBytes added in v1.2.3

func (d *DataCache) EnsureNBytes(ctx context.Context, want int)

func (*DataCache) Evict added in v1.2.3

func (d *DataCache) Evict(ctx context.Context, ch chan int64)

func (*DataCache) EvictToTargetWithWait

func (d *DataCache) EvictToTargetWithWait(ctx context.Context, target int64) int64

func (*DataCache) Flush added in v1.2.3

func (d *DataCache) Flush(ctx context.Context)

func (*DataCache) ForceEvictWithWait

func (d *DataCache) ForceEvictWithWait(ctx context.Context, n int64) int64

func (*DataCache) Get added in v1.2.3

func (d *DataCache) Get(ctx context.Context, key query.CacheKey) (fscache.Data, bool)

func (*DataCache) Set added in v1.2.3

func (d *DataCache) Set(ctx context.Context, key query.CacheKey, value fscache.Data) error

func (*DataCache) SetAdmissionTarget

func (d *DataCache) SetAdmissionTarget(admissionTarget func(capacity int64) (int64, bool))

func (*DataCache) Used added in v1.2.3

func (d *DataCache) Used() int64

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue[T any]() *Queue[T]

Jump to

Keyboard shortcuts

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