aeus/pkg/cache/cache.go

43 lines
954 B
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.
Get(ctx context.Context, key string) (any, error)
// Put stores a key-value pair into cache.
Put(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 Get(ctx context.Context, key string) (any, error) {
return std.Get(ctx, key)
}
// Put stores a key-value pair into cache.
func Put(ctx context.Context, key string, val any, d time.Duration) error {
return std.Put(ctx, key, val, d)
}
// String returns the name of the implementation.
func Delete(ctx context.Context, key string) error {
return std.Delete(ctx, key)
}