update: readme.md; feat: add flag

This commit is contained in:
loveuer
2025-01-01 21:01:05 -08:00
parent 25b36157c7
commit a9039115d8
13 changed files with 192 additions and 75 deletions

1
pkg/cache/cache.go vendored
View File

@ -19,6 +19,7 @@ type Cache interface {
// SetEx value 会被序列化, 优先使用 MarshalBinary 方法, 没有则执行 json.Marshal
SetEx(ctx context.Context, key string, value any, duration time.Duration) error
Del(ctx context.Context, keys ...string) error
Close() error
}
type Scanner interface {

View File

@ -134,6 +134,11 @@ func (l *_lru) Del(ctx context.Context, keys ...string) error {
return nil
}
func (l *_lru) Close() error {
l.client = nil
return nil
}
func newLRUCache() (Cache, error) {
client := expirable.NewLRU[string, *_lru_value](1024*1024, nil, 0)

View File

@ -103,3 +103,9 @@ func (m *_mem) Del(ctx context.Context, keys ...string) error {
m.client.Delete(keys...)
return nil
}
func (m *_mem) Close() error {
m.client = nil
return nil
}

View File

@ -104,3 +104,7 @@ func (r *_redis) SetEx(ctx context.Context, key string, value any, duration time
func (r *_redis) Del(ctx context.Context, keys ...string) error {
return r.client.Del(ctx, keys...).Err()
}
func (r *_redis) Close() error {
return r.client.Close()
}