Documentation ¶
Index ¶
- type Cache
- func (c *Cache[K, V]) Add(key K, value V)
- func (c *Cache[K, V]) AddWithExpiry(key K, value V, expiry time.Duration)
- func (c *Cache[K, V]) Get(key K) (result V, found bool)
- func (c Cache[K, V]) GetDefaultExpiration() time.Duration
- func (c *Cache[K, V]) GetKeys() (keys []K)
- func (c *Cache[K, V]) Len() (count int)
- func (c *Cache[K, V]) Size() int
- type Cacher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache implements the Cacher interface
func New ¶
func New[K comparable, V any](expiration, cleanup time.Duration) (c *Cache[K, V])
New creates a new Cache for the specified key and value types. expiration specifies the default time an entry can live in the cache before expiring. cleanup specifies how often the cache will remove expired items.
func (*Cache[K, V]) Add ¶
func (c *Cache[K, V]) Add(key K, value V)
Add adds a key/value pair to the cache, using the default expiry time
func (*Cache[K, V]) AddWithExpiry ¶ added in v0.0.2
AddWithExpiry adds a key/value pair to the cache with a specified expiry time
func (*Cache[K, V]) Get ¶
Get returns the value from the cache for the provided key. If the item is not found, or expired, found will be false
func (Cache[K, V]) GetDefaultExpiration ¶ added in v0.0.4
GetDefaultExpiration returns the default expiration time of the cache
func (*Cache[K, V]) GetKeys ¶ added in v0.0.5
func (c *Cache[K, V]) GetKeys() (keys []K)
GetKeys returns all keys in the cache.