golib/gcache/adapter_local.go

49 lines
862 B
Go

//
// adapter_local.go
// Copyright (C) 2022 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
package gcache
import (
"sync"
"time"
"git.hexq.cn/tiglog/golib/helper"
)
const default_cache_size = 1024
// 本地内存缓存
type localCacheAdapter struct {
mu sync.Mutex
data map[string][]byte
}
func NewLocalCacheAdapter() ICacheAdapter {
return &localCacheAdapter{
data: make(map[string][]byte, default_cache_size),
}
}
func (c *localCacheAdapter) Get(key string, dest interface{}) error {
val, ok := c.data[key]
if ok {
helper.Scan(val, dest)
}
return nil
}
func (c *localCacheAdapter) Set(key string, val interface{}, ttl time.Duration) error {
return nil
}
func (c *localCacheAdapter) Has(key string) bool {
return false
}
func (c *localCacheAdapter) Del(keys ...string) (int64, error) {
return 0, nil
}