Documentation
¶
Overview ¶
Package ttl provides a synchronised map that auto-expire
This package is simply to provide a storage for session.
Index ¶
- type Cache
- func (c *Cache[K, V]) Delete(key K)
- func (c *Cache[K, V]) Destroy()
- func (c *Cache[K, V]) Get(key K) (v V)
- func (c *Cache[K, V]) GetAndDelete(key K) (v V)
- func (c *Cache[K, V]) GetOrSet(key K, val V) (v V)
- func (c *Cache[K, V]) Range(f func(K, V) error) error
- func (c *Cache[K, V]) Set(key K, val V)
- func (c *Cache[K, V]) Touch(key K, ttl time.Duration)
- type Item
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 is a synchronised map of items that auto-expire once stale
func NewCache ¶
func NewCache[K comparable, V any](ttl time.Duration) *Cache[K, V]
NewCache 创建指定生命周期的 Cache
func NewCacheOn ¶
func NewCacheOn[K comparable, V any](ttl time.Duration, on [4]func(K, V)) *Cache[K, V]
NewCacheOn 创建指定生命周期的 Cache
on: [onset, onget, ondel, ontouch]
func (*Cache[K, V]) GetAndDelete ¶
func (c *Cache[K, V]) GetAndDelete(key K) (v V)
Delete 获得值后删除指定key
Click to show internal directories.
Click to hide internal directories.