cache

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRUCache

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

LRUCache provides a simple LRU cache with both size and TTL limits. It uses RWMutex for optimal concurrent access patterns - multiple concurrent reads are allowed while writes get exclusive access.

func NewLRUCache

func NewLRUCache(maxSize int, ttl time.Duration) *LRUCache

NewLRUCache creates a new LRU cache with the specified maximum size and TTL.

func (*LRUCache) Add

func (c *LRUCache) Add(key string)

Add marks a key as cached. This operation uses a write lock for exclusive access. If the key already exists, its expiration time is updated and it's moved to the end of the LRU order. If the cache exceeds maxSize, oldest entries are evicted.

func (*LRUCache) Clear

func (c *LRUCache) Clear()

Clear removes all entries from the cache.

func (*LRUCache) Delete

func (c *LRUCache) Delete(key string)

Delete removes a key from the cache.

func (*LRUCache) Has

func (c *LRUCache) Has(key string) bool

Has checks if key exists and hasn't expired. This operation uses a read lock, allowing concurrent access.

func (*LRUCache) Size

func (c *LRUCache) Size() int

Size returns the current number of entries in the cache.

Jump to

Keyboard shortcuts

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