39 lines
938 B
Go
39 lines
938 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, time.Time, 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
|
|
}
|
|
|
|
// Get gets a cached value by key.
|
|
func Get(ctx context.Context, key string) (any, time.Time, 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)
|
|
}
|