Documentation
¶
Index ¶
Examples ¶
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 { *sync.RWMutex // contains filtered or unexported fields }
Cache is a simple cache and has only supports manual eviction.
Example ¶
package main
import (
"fmt"
"github.com/bir/iken/cache"
)
func main() {
c := cache.NewCache[string, int]()
c.Set("a", 1)
out, ok := c.Get("a")
fmt.Println(out, ok)
out, ok = c.Get("b")
fmt.Println(out, ok)
c.Set("b", 2)
kk := c.Keys()
fmt.Println(kk)
c.Delete("a")
kk = c.Keys()
fmt.Println(kk)
}
Output: 1 true 0 false [a b] [b]
func NewCache ¶
func NewCache[K comparable, V any]() *Cache[K, V]
NewCache creates a new non-thread safe cache.
func (*Cache[K, V]) Delete ¶
func (c *Cache[K, V]) Delete(key K)
Delete deletes the item with provided key from the cache.
func (*Cache[K, V]) Get ¶
Get gets an item from the cache. Returns the item or zero value, and a bool indicating whether the key was found.
type NoOpCache ¶
type NoOpCache[K comparable, V any] struct{}
NoOpCache is a facade cache, it never returns a hit. Useful for easily disabling cache at runtime.
func NewNoOpCache ¶
func NewNoOpCache[K comparable, V any]() *NoOpCache[K, V]
NewNoOpCache creates a new NOP cache.
Click to show internal directories.
Click to hide internal directories.