Documentation ¶
Overview ¶
Package cache provides a type-safe in-memory cache implementation.
Index ¶
- type Cache
- func (c *Cache[T]) Delete(key string)
- func (c *Cache[T]) DeleteMatchingEntries(fn func(T) bool)
- func (c *Cache[T]) Filter(fn func(T) bool) []T
- func (c *Cache[T]) Get(key string) (T, bool)
- func (c *Cache[T]) Prune(key string)
- func (c *Cache[T]) Set(key string, data T, exp time.Duration)
- func (c *Cache[T]) Size() uint64
- type CacheEntry
- type CacheOption
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
Cache implements a type-safe in-memory cache
func New ¶
func New[T any](options ...CacheOption) *Cache[T]
New creates a new cache instance with the provided options.
func (*Cache[T]) DeleteMatchingEntries ¶
DeleteMatchingEntries deletes cache entries that match the given filter function.
func (*Cache[T]) Filter ¶
Filter applies a filter function to the cache entries and returns a slice of filtered values.
func (*Cache[T]) Get ¶
Get retrieves the value associated with the given key from the cache. If the key is not found or if the entry has expired, it returns the zero value of type T and false. Otherwise, it returns the value and true.
type CacheEntry ¶
type CacheEntry[T any] struct { // contains filtered or unexported fields }
CacheEntry holds the cached data and its expiration time
type CacheOption ¶
type CacheOption interface {
// contains filtered or unexported methods
}
func WithCapacity ¶
func WithCapacity(o uint64) CacheOption
Click to show internal directories.
Click to hide internal directories.