cache

package
v0.0.0-...-445c557 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 5 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 represents a distributed cache with multiple shards for concurrency and efficiency. Each shard manages a subset of cache entries to reduce contention.

func New

func New(numShards, capacity int, ttl time.Duration) *Cache

Initializes and returns a new `Cache` instance. It distributes the capacity evenly across all shards.

func (*Cache) Get

func (c *Cache) Get(req *pb.GetRequest) (*pb.GetResponse, bool)

Retrieves a cache entry by key and returns a GetResponse if the key exists and has not expired. If the item is found, it is moved to the front of the eviction list to mark it as recently used.

func (*Cache) Set

func (c *Cache) Set(req *pb.SetRequest)

Set adds or updates a cache entry with the specified key and value from the SetRequest. If the cache exceeds its capacity, the least-recently-used (LRU) item is evicted.

Jump to

Keyboard shortcuts

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