Documentation ¶
Overview ¶
relevantcache package manages "relevant" cache keys in some cache backend (now redis).
Describe:
Occasionally some of caches have relevant like:
cacheA -> cacheB -> cacheC ...
When cacheA has been destroyed, we also delete cacheB because they are relevant. And, when cacheB has been destroyed, cacheC will be destroyed.
Strategy:
Just simple. we prepend metadata that is relevant cache keys when store a cache data. When we get it, retrieve metadata and return cache data only, and when we delete it, extract metadata, factory relevant keys recursively, and delete those.
Index ¶
- Variables
- func KeyGen(args ...interface{}) string
- func WithDebugWriter(w io.Writer) option
- func WithSkipTLSVerify(skip bool) option
- type Cache
- type Item
- type MemoryCache
- func (m *MemoryCache) Close() error
- func (m *MemoryCache) Del(items ...interface{}) error
- func (m *MemoryCache) Dump() string
- func (m *MemoryCache) Get(item interface{}) ([]byte, error)
- func (m *MemoryCache) HGet(key interface{}, field string) ([]byte, error)
- func (m *MemoryCache) HLen(key interface{}) (int64, error)
- func (m *MemoryCache) HSet(key interface{}, field string, value interface{}) error
- func (m *MemoryCache) Increment(key string) error
- func (m *MemoryCache) MGet(keys ...interface{}) ([][]byte, error)
- func (m *MemoryCache) Purge() error
- func (m *MemoryCache) Redis() *redis.Client
- func (m *MemoryCache) Set(args ...interface{}) (err error)
- func (m *MemoryCache) Unlink(keys ...interface{}) error
- type RedisCache
- func (r *RedisCache) Close() error
- func (r *RedisCache) Del(items ...interface{}) error
- func (r *RedisCache) Dump() string
- func (r *RedisCache) Get(item interface{}) ([]byte, error)
- func (r *RedisCache) HGet(key interface{}, field string) ([]byte, error)
- func (r *RedisCache) HLen(key interface{}) (int64, error)
- func (r *RedisCache) HSet(key interface{}, field string, value interface{}) error
- func (r *RedisCache) Increment(key string) error
- func (r *RedisCache) MGet(keys ...interface{}) ([][]byte, error)
- func (r *RedisCache) Purge() error
- func (r *RedisCache) Redis() *redis.Client
- func (r *RedisCache) Set(args ...interface{}) (err error)
- func (r *RedisCache) Unlink(items ...interface{}) error
Constants ¶
This section is empty.
Variables ¶
var RedisNil = redis.Nil
Functions ¶
func WithDebugWriter ¶
func WithSkipTLSVerify ¶
func WithSkipTLSVerify(skip bool) option
Types ¶
type Cache ¶
type Cache interface { Get(item interface{}) ([]byte, error) Set(args ...interface{}) error Del(items ...interface{}) error Unlink(items ...interface{}) error Increment(key string) error Close() error Dump() string Purge() error MGet(keys ...interface{}) ([][]byte, error) HSet(key interface{}, field string, value interface{}) error HLen(key interface{}) (int64, error) HGet(key interface{}, field string) ([]byte, error) Redis() *redis.Client // should return *redis.Client if you are using *RedisCache otherwise nil }
All methods accepts as interface{} because argument can be passed as string or *Item
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Relevant item struct If you have relevant keys, create pointer of this struct and pass to methods
func NewItem ¶
func NewItem(args ...interface{}) *Item
Crate Item pointer. argment accepts any amounts, types. Arguments becomes cache key.
func (*Item) RelevantAll ¶
Declare relevant cache keys with asterisk sign suffix
func (*Item) RelevantTo ¶
Declare relevant cache keys
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
func NewMemoryCache ¶
func NewMemoryCache(opts ...option) *MemoryCache
func (*MemoryCache) Close ¶
func (m *MemoryCache) Close() error
func (*MemoryCache) Del ¶
func (m *MemoryCache) Del(items ...interface{}) error
func (*MemoryCache) Dump ¶
func (m *MemoryCache) Dump() string
func (*MemoryCache) Get ¶
func (m *MemoryCache) Get(item interface{}) ([]byte, error)
func (*MemoryCache) HGet ¶ added in v0.12.0
func (m *MemoryCache) HGet(key interface{}, field string) ([]byte, error)
func (*MemoryCache) HLen ¶ added in v0.12.0
func (m *MemoryCache) HLen(key interface{}) (int64, error)
func (*MemoryCache) HSet ¶ added in v0.12.0
func (m *MemoryCache) HSet(key interface{}, field string, value interface{}) error
func (*MemoryCache) Increment ¶
func (m *MemoryCache) Increment(key string) error
func (*MemoryCache) MGet ¶ added in v0.11.0
func (m *MemoryCache) MGet(keys ...interface{}) ([][]byte, error)
func (*MemoryCache) Purge ¶
func (m *MemoryCache) Purge() error
func (*MemoryCache) Redis ¶ added in v0.12.1
func (m *MemoryCache) Redis() *redis.Client
func (*MemoryCache) Set ¶
func (m *MemoryCache) Set(args ...interface{}) (err error)
func (*MemoryCache) Unlink ¶ added in v0.11.3
func (m *MemoryCache) Unlink(keys ...interface{}) error
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
Redis backend struct
func NewRedisCache ¶
func NewRedisCache(endpoint string, opts ...option) (*RedisCache, error)
Create RedisCache pointer with some options Currently enabled options are:
rc.WithSkipTLSVerify(bool): Skip TLS verification
func (*RedisCache) Del ¶
func (r *RedisCache) Del(items ...interface{}) error
Wrap of redis.DEL item is acceptable either of string of *Item
func (*RedisCache) Dump ¶
func (r *RedisCache) Dump() string
func (*RedisCache) Get ¶
func (r *RedisCache) Get(item interface{}) ([]byte, error)
Wrap of redis.GET item is acceptable either of string of *Item
func (*RedisCache) HGet ¶ added in v0.12.0
func (r *RedisCache) HGet(key interface{}, field string) ([]byte, error)
func (*RedisCache) HLen ¶ added in v0.12.0
func (r *RedisCache) HLen(key interface{}) (int64, error)
func (*RedisCache) HSet ¶ added in v0.12.0
func (r *RedisCache) HSet(key interface{}, field string, value interface{}) error
func (*RedisCache) Increment ¶
func (r *RedisCache) Increment(key string) error
func (*RedisCache) MGet ¶ added in v0.11.0
func (r *RedisCache) MGet(keys ...interface{}) ([][]byte, error)
func (*RedisCache) Redis ¶ added in v0.12.1
func (r *RedisCache) Redis() *redis.Client
func (*RedisCache) Set ¶
func (r *RedisCache) Set(args ...interface{}) (err error)
Wrap of redis.SET/redis.SETEX args is acceptable with following argument counts:
count is 1: deal with *Item count is 2: deal with first argument as cache key, second argument as value. TTL is 0 (no expiration) count is 3: deal with first argument as cache key, second argument as value, third argument as TTL
func (*RedisCache) Unlink ¶ added in v0.11.3
func (r *RedisCache) Unlink(items ...interface{}) error
Wrap of redis.UNLINK, note that ensure your redis engine is later than v4 item is acceptable either of string of *Item