Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidType = errors.New("invalid type")
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Example ¶
package main
import (
"context"
"fmt"
"time"
"github.com/worldline-go/cache"
)
func main() {
cfg := cache.Config{
MaxItems: 1_000,
TTL: 30 * time.Minute,
}
c, err := cache.New(context.Background(), cfg.ToOption())
if err != nil {
panic(err)
}
vcache, err := cache.Port[string, int](c)
if err != nil {
panic(err)
}
if err := vcache.Set("key", 42); err != nil {
panic(err)
}
v, ok, err := vcache.Get("key")
if err != nil {
panic(err)
}
if !ok {
panic("key not found")
}
fmt.Println(v)
}
Output: 42
type Cacher ¶
type Cacher[K comparable, V any] interface { Get(key K) (V, bool, error) Set(key K, value V) error }
type Config ¶
type Option ¶
type Option func(*option)
func WithMaxItems ¶
WithMaxItems sets the maximum number of items the cache can hold.
func WithTypeStorage ¶
WithTypeStorage sets the type of cache to use.
Click to show internal directories.
Click to hide internal directories.