Documentation ¶
Index ¶
- func Marshal(val interface{}) ([]byte, bool)
- func MarshalString(val interface{}) (string, bool)
- func Unmarshal(buf []byte, val interface{}) bool
- func UnmarshalString(buf string, val interface{}) bool
- 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 CachexGorm
- func (c *CachexGorm[T]) Close()
- func (c *CachexGorm[T]) Delete(key string)
- func (c *CachexGorm[T]) Free()
- func (c *CachexGorm[T]) Get(key string) (T, bool)
- func (c *CachexGorm[T]) GetDBInterface() *gorm.DB
- func (c *CachexGorm[T]) NewModel() CachexGormModel
- func (c *CachexGorm[T]) Range(f func(key string, value T) bool)
- func (c *CachexGorm[T]) Set(key string, value T)
- type CachexGormModel
- type Data
- type Eviction
- type FifoCache
- type JsonByteData
- type LeveldbCache
- func (c *LeveldbCache[T]) Close()
- func (c *LeveldbCache[T]) Delete(key string)
- func (c *LeveldbCache[T]) Free()
- func (c *LeveldbCache[T]) Get(key string) (T, bool)
- func (c *LeveldbCache[T]) GetDBInterface() *leveldb.DB
- func (c *LeveldbCache[T]) Range(f func(key string, value T) bool)
- func (c *LeveldbCache[T]) Set(key string, value T)
- func (c *LeveldbCache[T]) Unmarshal(data []byte) (T, bool)
- type LfuCache
- type LruCache
- type RedisCache
- func (c *RedisCache[T]) Close()
- func (c *RedisCache[T]) Delete(key string)
- func (c *RedisCache[T]) Free()
- func (c *RedisCache[T]) Get(key string) (T, bool)
- func (c *RedisCache[T]) GetDBInterface() *redis.Client
- func (c *RedisCache[T]) Range(f func(key string, value T) bool)
- func (c *RedisCache[T]) Set(key string, value T)
- type RedisConfig
- type SliceMap
- func (SliceMap) Close()
- func (m *SliceMap[T]) Delete(key string)
- func (m *SliceMap[T]) Get(key string) (T, bool)
- func (m *SliceMap[T]) Len() int
- func (m *SliceMap[T]) Pop() (T, bool)
- func (m *SliceMap[T]) Range(fn func(key string, value T) (Continue bool))
- func (m *SliceMap[T]) Set(key string, value T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalString ¶ added in v0.0.8
func UnmarshalString ¶ added in v0.0.8
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 CachexGorm ¶ added in v0.0.8
type CachexGorm[T any] struct { // contains filtered or unexported fields }
func NewGormCachex ¶ added in v0.0.8
func NewGormCachex[T any](db *gorm.DB, tableName ...string) *CachexGorm[T]
func NewSqliteCache ¶ added in v0.0.8
func NewSqliteCache[T any](dbPath string, tableName ...string) (*CachexGorm[T], error)
func (*CachexGorm[T]) Close ¶ added in v0.0.8
func (c *CachexGorm[T]) Close()
func (*CachexGorm[T]) Delete ¶ added in v0.0.8
func (c *CachexGorm[T]) Delete(key string)
func (*CachexGorm[T]) Free ¶ added in v0.0.8
func (c *CachexGorm[T]) Free()
func (*CachexGorm[T]) Get ¶ added in v0.0.8
func (c *CachexGorm[T]) Get(key string) (T, bool)
func (*CachexGorm[T]) GetDBInterface ¶ added in v0.0.8
func (c *CachexGorm[T]) GetDBInterface() *gorm.DB
func (*CachexGorm[T]) NewModel ¶ added in v0.0.8
func (c *CachexGorm[T]) NewModel() CachexGormModel
func (*CachexGorm[T]) Range ¶ added in v0.0.8
func (c *CachexGorm[T]) Range(f func(key string, value T) bool)
func (*CachexGorm[T]) Set ¶ added in v0.0.8
func (c *CachexGorm[T]) Set(key string, value T)
type CachexGormModel ¶ added in v0.0.8
type CachexGormModel struct { ID int64 `gorm:"id"` Key string `gorm:"key"` Value string `gorm:"value"` // contains filtered or unexported fields }
func (CachexGormModel) TableName ¶ added in v0.0.8
func (c CachexGormModel) TableName() string
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]) Range ¶ added in v0.0.8
func (c *LeveldbCache[T]) Range(f func(key string, value T) bool)
遍历数据
func (*LeveldbCache[T]) Set ¶ added in v0.0.3
func (c *LeveldbCache[T]) Set(key string, value T)
设置缓存
func (*LeveldbCache[T]) Unmarshal ¶ added in v0.0.8
func (c *LeveldbCache[T]) Unmarshal(data []byte) (T, bool)
反序化数据
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实例对象
func (*RedisCache[T]) Range ¶ added in v0.0.8
func (c *RedisCache[T]) Range(f func(key string, value T) bool)
遍历数据
type RedisConfig ¶
type RedisConfig = redis.Options
Source Files ¶
Click to show internal directories.
Click to hide internal directories.