aeus/pkg/cache/cache.go

45 lines
1.0 KiB
Go

package cache
import (
"context"
"time"
"git.nobla.cn/golang/aeus/pkg/cache/memory"
)
var (
std = memory.NewCache()
)
type Cache interface {
// Get gets a cached value by key.
Load(ctx context.Context, key string, val any) error
// Get gets a cached value by key.
Exists(ctx context.Context, key string) (bool, error)
// Put stores a key-value pair into cache.
Store(ctx context.Context, key string, val any, d time.Duration) error
// Delete removes a key from cache.
Delete(ctx context.Context, key string) error
// String returns the name of the implementation.
String() string
}
func Default() Cache {
return std
}
// Get gets a cached value by key.
func Load(ctx context.Context, key string, val any) error {
return std.Load(ctx, key, val)
}
// Put stores a key-value pair into cache.
func Store(ctx context.Context, key string, val any, d time.Duration) error {
return std.Store(ctx, key, val, d)
}
// String returns the name of the implementation.
func Delete(ctx context.Context, key string) error {
return std.Delete(ctx, key)
}