Documentation ¶
Index ¶
- Variables
- type Cache
- func (cd *Cache) CleanLocalCache()
- func (cd *Cache) Delete(ctx context.Context, key string) error
- func (cd *Cache) DeleteFromLocalCache(key string)
- func (cd *Cache) Exists(ctx context.Context, key string) bool
- func (cd *Cache) Get(ctx context.Context, key string, value any) error
- func (cd *Cache) GetSkip(ctx context.Context, key string, value any, mode SkipMode) error
- func (cd *Cache) GetSkippingLocalCache(ctx context.Context, key string, value any) error
- func (cd *Cache) Marshal(value any) ([]byte, error)
- func (cd *Cache) Once(item *Item) error
- func (cd *Cache) Set(item *Item) error
- func (cd *Cache) Stats() *Stats
- func (cd *Cache) Take(item *Item) error
- func (cd *Cache) Unmarshal(b []byte, value any) error
- type Item
- type LocalCache
- type MarshalFunc
- type Option
- type Options
- type Redisc
- func (c *Redisc) Apply(cfg *conf.Configuration)
- func (c *Redisc) Del(ctx context.Context, key string) error
- func (c *Redisc) Get(ctx context.Context, key string, v any) error
- func (c *Redisc) Has(ctx context.Context, key string) bool
- func (c *Redisc) IsNotFound(err error) bool
- func (c *Redisc) LocalCacheEnabled() bool
- func (c *Redisc) Operator() *Cache
- func (c *Redisc) RedisClient() redis.Cmdable
- func (c *Redisc) Register() error
- func (c *Redisc) Set(ctx context.Context, key string, v any, ttl time.Duration) error
- func (c *Redisc) Take(ctx context.Context, v any, key string, ttl time.Duration, ...) error
- type SkipMode
- type Stats
- type TinyLFU
- type UnmarshalFunc
Constants ¶
This section is empty.
Variables ¶
var (
ErrCacheMiss = errors.New("cache: key is missing")
)
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func (*Cache) CleanLocalCache ¶ added in v0.1.0
func (cd *Cache) CleanLocalCache()
func (*Cache) DeleteFromLocalCache ¶
func (*Cache) Exists ¶
Exists reports whether value for the given key exists. exists call get ,ttl is unknown
func (*Cache) GetSkippingLocalCache ¶
GetSkippingLocalCache gets the value for the given key skipping local cache.
func (*Cache) Once ¶
Once gets the item.Value for the given item.Key from the cache or executes, caches, and returns the results of the given item.Func, making sure that only one execution is in-flight for a given item.Key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.
func (*Cache) Set ¶
Set caches the item. Notice: If you use SkipXXX flags, you must Use GetSkip() to get the value. once you use unmatched method such as Get/Exists to get or check the value, the local cache don't know the flags and will cause mess .
type Item ¶
type Item struct { Ctx context.Context Key string Value any // TTL is the cache expiration time. // Default TTL is 1 hour. TTL time.Duration // Do returns value to be cached. Do func(*Item) (any, error) // SetXX only sets the key if it already exists. SetXX bool // SetNX only sets the key if it does not already exist. SetNX bool // SkipFlags indicator skip level. Skip SkipMode }
type LocalCache ¶
type LocalCache interface { // Set sets a value for a key. ttl maybe has a rule in Local Cache Set(key string, data []byte, ttl time.Duration) Get(key string) ([]byte, bool) Del(key string) // Clean removes all items from the cache in memory. Clean() }
LocalCache is a local cache to store a marshalled data in memory.
type MarshalFunc ¶
------------------------------------------------------------------------------
type Option ¶ added in v0.1.0
type Option func(*Redisc)
func WithRedisClient ¶ added in v0.1.0
func WithRedisClient(cli redis.UniversalClient) Option
type Options ¶
type Options struct { Redis rediser LocalCache LocalCache LocalCacheTTL time.Duration StatsEnabled bool Marshal MarshalFunc Unmarshal UnmarshalFunc }
type Redisc ¶
type Redisc struct {
// contains filtered or unexported fields
}
Redisc implement github.com/tsingsun/woocoo/cache/Cache
if you want to register to cache manager, set a `driverName` in configuration
func NewBuiltIn ¶
func NewBuiltIn() *Redisc
func (*Redisc) IsNotFound ¶
IsNotFound returns true if the error is cache.ErrCacheMiss.
func (*Redisc) LocalCacheEnabled ¶ added in v0.1.0
LocalCacheEnabled returns true if local cache is enabled.
func (*Redisc) RedisClient ¶
func (c *Redisc) RedisClient() redis.Cmdable
RedisClient returns the underlying redis client.
type TinyLFU ¶
type TinyLFU struct {
// contains filtered or unexported fields
}
func (*TinyLFU) UseRandomizedTTL ¶
type UnmarshalFunc ¶
------------------------------------------------------------------------------