Documentation
¶
Overview ¶
Package cache provides a simple in-memory cache with optional TTL and weak reference support.
Index ¶
- type Cache
- func (c *Cache[T]) Cleanup() int
- func (c *Cache[T]) Clear()
- func (c *Cache[T]) Delete(key string)
- func (c *Cache[T]) Get(key string) (*T, bool)
- func (c *Cache[T]) Len() int
- func (c *Cache[T]) Set(key string, value *T, ttl time.Duration)
- func (c *Cache[T]) StartCleanupTimer(interval time.Duration) func()
- type Entry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache is a simple in-memory cache with optional TTL support and weak references.
func (*Cache[T]) Cleanup ¶
Cleanup removes all expired entries and entries with GC'd values. This can be called periodically to free memory.
func (*Cache[T]) Get ¶
Get retrieves a value from the cache. Returns the value and true if found, not expired, and not GC'd; nil and false otherwise.
func (*Cache[T]) Set ¶
Set stores a value with an optional TTL using weak references. If ttl is 0, the entry never expires (but can still be GC'd due to weak reference).
func (*Cache[T]) StartCleanupTimer ¶
StartCleanupTimer starts a periodic cleanup of expired and GC'd entries. Returns a function to stop the cleanup timer.