Documentation ¶
Index ¶
- type Cache
- func (c *Cache[T]) Close()
- func (c *Cache[T]) Create(key string, value T)
- func (c *Cache[T]) Delete(key string)
- func (c *Cache[T]) Free()
- func (c *Cache[T]) Get(key string) (T, bool)
- func (c *Cache[T]) GetOrSet(key string, value T) (oldValue T, isLoad bool)
- func (c *Cache[T]) GetOrSetFunc(key string, setFn func() (value T, canSet bool)) (oldValue T, isLoad bool)
- func (c *Cache[T]) Save(key string, value T)
- func (c *Cache[T]) Set(key string, value T)
- func (c *Cache[T]) SetFunc(key string, fn func() (value T, canSet bool))
- func (c *Cache[T]) Swap(key string, value T) (oldValue T, isLoad bool)
- type CacheStroage
- type Data
- type Eviction
- type FifoCache
- type JsonByteData
- type LeveldbCache
- type LfuCache
- type LruCache
- type RedisCache
- type RedisConfig
- type SliceMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
func NewCache ¶
func NewCache(defaultcache CacheStroage[any], remotecache ...CacheStroage[any]) *Cache[any]
默认创any类型的存储
func NewCacheWithType ¶
func NewCacheWithType[T any](defaultcache CacheStroage[T], remotecache ...CacheStroage[T]) *Cache[T]
带有类型的存储
func (*Cache[T]) GetOrSetFunc ¶
func (c *Cache[T]) GetOrSetFunc(key string, setFn func() (value T, canSet bool)) (oldValue T, isLoad bool)
获取失败时则通过指定函数设置为指定值
type CacheStroage ¶
type FifoCache ¶ added in v0.0.4
type FifoCache[T any] struct { // contains filtered or unexported fields }
func NewMemFifoCacheStroage ¶ added in v0.0.4
Fifo最近最先加入缓存的数据最先被淘汰
func NewMemFifoCacheStroageWithType ¶ added in v0.0.4
Fifo最近最先加入缓存的数据最先被淘汰
type JsonByteData ¶
type JsonByteData[T any] struct { Data T `json:"Data"` }
type LeveldbCache ¶ added in v0.0.3
type LeveldbCache[T any] struct { // contains filtered or unexported fields }
func NewLevelDBCacheStroage ¶ added in v0.0.3
func NewLevelDBCacheStroage(dbpath string) (*LeveldbCache[any], error)
Leveldb最近最少被使用的数据最先被淘汰
func NewLevelDBCacheStroageWithType ¶ added in v0.0.3
func NewLevelDBCacheStroageWithType[T any](dbpath string) (*LeveldbCache[T], error)
Leveldb最近最少被使用的数据最先被淘汰
func (*LeveldbCache[T]) Get ¶ added in v0.0.3
func (c *LeveldbCache[T]) Get(key string) (T, bool)
获取缓存
func (*LeveldbCache[T]) GetDBInterface ¶ added in v0.0.5
func (c *LeveldbCache[T]) GetDBInterface() *leveldb.DB
获取DB实例对象
func (*LeveldbCache[T]) Set ¶ added in v0.0.3
func (c *LeveldbCache[T]) Set(key string, value T)
设置缓存
type LfuCache ¶ added in v0.0.3
type LfuCache[T any] struct { UpperBound int LowerBound int EvictionChannel chan<- Eviction[T] // contains filtered or unexported fields }
func NewMemLfuCacheStroage ¶ added in v0.0.3
Lfu使用频率最低的数据最先被淘汰
func NewMemLfuCacheStroageWithType ¶ added in v0.0.3
Lfu使用频率最低的数据最先被淘汰
type LruCache ¶
type LruCache[T any] struct { // contains filtered or unexported fields }
func NewMemLruCacheStroage ¶
Lru最近最少被使用的数据最先被淘汰
func NewMemLruCacheStroageWithType ¶
Lru最近最少被使用的数据最先被淘汰
type RedisCache ¶
type RedisCache[T any] struct { // contains filtered or unexported fields }
func NewRedisCacheStroage ¶
func NewRedisCacheStroage(config *RedisConfig, timeout ...time.Duration) *RedisCache[any]
Redis存储 传入连接参数和缓存超时时间
func NewRedisCacheStroageWithType ¶
func NewRedisCacheStroageWithType[T any](config *RedisConfig, timeout ...time.Duration) *RedisCache[T]
Redis存储 传入连接参数和缓存超时时间
func (*RedisCache[T]) Close ¶ added in v0.0.6
func (c *RedisCache[T]) Close()
func (*RedisCache[T]) GetDBInterface ¶ added in v0.0.5
func (c *RedisCache[T]) GetDBInterface() *redis.Client
获取DB实例对象
type RedisConfig ¶
type RedisConfig = redis.Options
Source Files ¶
Click to show internal directories.
Click to hide internal directories.