Documentation ¶
Index ¶
- Constants
- Variables
- func Decrement(originVal any, step int) (any, error)
- func Increment(originVal any, step int) (any, error)
- type Cache
- type CacheItem
- func (c *CacheItem) GetCacheItem(data any) (item ICacheItem, err error)
- func (c *CacheItem) GetData() any
- func (c *CacheItem) GetExpirationTime() time.Time
- func (c *CacheItem) GetJoinTime() time.Time
- func (c *CacheItem) GetTTL() time.Duration
- func (c *CacheItem) IsNeverExpires() bool
- func (c *CacheItem) SetCacheItem(data any, ttl time.Duration) (string, error)
- type CacheManager
- type FileCache
- func (f *FileCache) Clear() error
- func (f *FileCache) Decrement(key string, step int) error
- func (f *FileCache) Delete(key string) error
- func (f *FileCache) DeleteMultiple(keys []string) error
- func (f *FileCache) Get(key string) (any, error)
- func (f *FileCache) GetMulti(keys []string) ([]any, error)
- func (f *FileCache) Has(key string) (bool, error)
- func (f *FileCache) Increment(key string, step int) error
- func (f *FileCache) Name() string
- func (f *FileCache) Set(key string, val any, ttl time.Duration) error
- type FileCacheOptions
- type GoCache
- func (f *GoCache) Clear() error
- func (f *GoCache) Decrement(key string, step int) error
- func (f *GoCache) Delete(key string) error
- func (f *GoCache) Disk(name string) CacheManager
- func (f *GoCache) Extend(cache Cache, names ...string) CacheManager
- func (f *GoCache) FindAdapter() Cache
- func (f *GoCache) Get(key string) (any, error)
- func (f *GoCache) GetMulti(keys []string) ([]any, error)
- func (f *GoCache) Has(key string) (bool, error)
- func (f *GoCache) Increment(key string, step int) error
- func (f *GoCache) Name() string
- func (f *GoCache) Pull(key string) (any, error)
- func (f *GoCache) Remember(key string, value any, ttl time.Duration) (any, error)
- func (f *GoCache) Set(key string, value any, ttl time.Duration) error
- type ICacheItem
- type MemoryCache
- func (m *MemoryCache) Clear() error
- func (m *MemoryCache) ClearExpiredKeys()
- func (m *MemoryCache) Decrement(key string, step int) error
- func (m *MemoryCache) Delete(key string) error
- func (m *MemoryCache) Get(key string) (any, error)
- func (m *MemoryCache) GetMulti(keys []string) ([]any, error)
- func (m *MemoryCache) Has(key string) (bool, error)
- func (m *MemoryCache) Increment(key string, step int) error
- func (m *MemoryCache) Name() string
- func (m *MemoryCache) Set(key string, value any, ttl time.Duration) error
Constants ¶
View Source
const ( MinUint32 uint32 = 0 MinUint64 uint64 = 0 FileCacheName = "file" MemoryCacheName = "memory" RedisCacheName = "redis" MemcacheCacheName = "memcache" CacheName = "go-cache" )
Variables ¶
View Source
var ( ErrKeyExpired = errors.New("the key is expired") ErrKeyNotExist = errors.New("the key isn't exist") )
View Source
var ( ErrIncrementOverflow = errors.New("this incr invocation will overflow") ErrDecrementOverflow = errors.New("this decr invocation will overflow") ErrNotIntegerType = errors.New("item val is not (u)int (u)int32 (u)int64 float64 float32") )
View Source
var (
FileCachePath = os.TempDir()
)
View Source
var IndefiniteTime = (86400 * 365 * 20) * time.Second
Functions ¶
Types ¶
type Cache ¶
type Cache interface { Name() string Set(key string, value any, ttl time.Duration) error Has(key string) (bool, error) GetMulti(keys []string) ([]any, error) Get(key string) (any, error) Delete(key string) error Increment(key string, step int) error Decrement(key string, step int) error Clear() error }
func NewFileCache ¶
func NewFileCache(opts ...FileCacheOptions) Cache
func NewMemoryCache ¶
NewMemoryCache returns a new MemoryCache.
type CacheItem ¶
type CacheItem struct { // data Data any `json:"data"` //expired ttl TTL time.Duration `json:"ttl"` // now data JoinTime time.Time `json:"join_time"` // expired data ExpirationTime time.Time `json:"expiration_time"` //Is it indefinite NeverExpires bool `json:"never_expires"` }
func (*CacheItem) GetCacheItem ¶
func (c *CacheItem) GetCacheItem(data any) (item ICacheItem, err error)
func (*CacheItem) GetExpirationTime ¶
func (*CacheItem) GetJoinTime ¶
func (*CacheItem) IsNeverExpires ¶
type CacheManager ¶
type CacheManager interface { Extend(cache Cache, names ...string) CacheManager Disk(name string) CacheManager Pull(key string) (any, error) Remember(key string, value any, ttl time.Duration) (any, error) Cache }
func New ¶
func New() CacheManager
func NewCache ¶
func NewCache(caches ...Cache) CacheManager
type FileCache ¶
type FileCache struct { Path string CacheItem ICacheItem }
func (*FileCache) DeleteMultiple ¶
type FileCacheOptions ¶
type FileCacheOptions func(c *FileCache)
func FileCacheWithCacheItem ¶
func FileCacheWithCacheItem(cacheItem ICacheItem) FileCacheOptions
func FileCacheWithCachePath ¶
func FileCacheWithCachePath(cachePath string) FileCacheOptions
type GoCache ¶
type GoCache struct { Maps map[string]Cache Names []string // contains filtered or unexported fields }
func (*GoCache) Disk ¶
func (f *GoCache) Disk(name string) CacheManager
func (*GoCache) Extend ¶
func (f *GoCache) Extend(cache Cache, names ...string) CacheManager
Extend 扩展
type ICacheItem ¶
type MemoryCache ¶
type MemoryCache struct { sync.RWMutex Interval time.Duration // contains filtered or unexported fields }
func (*MemoryCache) Clear ¶
func (m *MemoryCache) Clear() error
func (*MemoryCache) ClearExpiredKeys ¶
func (m *MemoryCache) ClearExpiredKeys()
func (*MemoryCache) Delete ¶
func (m *MemoryCache) Delete(key string) error
func (*MemoryCache) Name ¶
func (m *MemoryCache) Name() string
Click to show internal directories.
Click to hide internal directories.