Documentation
¶
Overview ¶
Package ttlcache implements an efficient cache with a TTL. Items in the cache are periodically purged in background.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K cacheKey, V any] struct { // contains filtered or unexported fields }
Cache is an efficient cache with a TTL.
func NewCache ¶
func NewCache[K cacheKey, V any](opts *CacheOptions) *Cache[K, V]
NewCache returns a new cache with a TTL.
func (*Cache[K, V]) Cleanup ¶
func (c *Cache[K, V]) Cleanup()
Cleanup removes all expired entries from the cache.
func (*Cache[K, V]) Get ¶
Get returns an item from the cache. Items that have expired are not returned.
type CacheOptions ¶
type CacheOptions struct {
// Initial size for the cache.
// This is optional, and if empty will be left to the underlying library to decide.
InitialSize int32
// Interval to perform garbage collection.
// This is optional, and defaults to 150s (2.5 minutes).
CleanupInterval time.Duration
// Maximum TTL value, if greater than 0
MaxTTL time.Duration
// contains filtered or unexported fields
}
CacheOptions are options for NewCache.
Click to show internal directories.
Click to hide internal directories.