Documentation ¶
Index ¶
- func SetVerbose(v bool)
- type Client
- func (c *Client) Fetch(key string, expire time.Duration, fn func() (string, error)) (string, error)
- func (c *Client) Fetch2(ctx context.Context, key string, expire time.Duration, ...) (string, error)
- func (c *Client) LockForUpdate(ctx context.Context, key string, owner string) error
- func (c *Client) RawGet(ctx context.Context, key string) (string, error)
- func (c *Client) RawSet(ctx context.Context, key string, value string, expire time.Duration) error
- func (c *Client) TagAsDeleted(key string) error
- func (c *Client) TagAsDeleted2(ctx context.Context, key string) error
- func (c *Client) UnlockForUpdate(ctx context.Context, key string, owner string) error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct { Options Options // contains filtered or unexported fields }
Client delay client
func NewClient ¶
NewClient return a new rockscache client for each key, rockscache client store a hash set, the hash set contains the following fields: value: the value of the key lockUtil: the time when the lock is released. lockOwner: the owner of the lock. if a thread query the cache for data, and no cache exists, it will lock the key before querying data in DB
func (*Client) Fetch ¶
Fetch returns the value store in cache indexed by the key. If the key doest not exists, call fn to get result, store it in cache, then return.
func (*Client) Fetch2 ¶
func (c *Client) Fetch2(ctx context.Context, key string, expire time.Duration, fn func() (string, error)) (string, error)
Fetch2 returns the value store in cache indexed by the key. If the key doest not exists, call fn to get result, store it in cache, then return.
func (*Client) LockForUpdate ¶
LockForUpdate locks the key, used in very strict strong consistency mode
func (*Client) RawGet ¶
RawGet returns the value store in cache indexed by the key, no matter if the key locked or not
func (*Client) RawSet ¶
RawSet sets the value store in cache indexed by the key, no matter if the key locked or not
func (*Client) TagAsDeleted ¶
TagAsDeleted a key, the key will expire after delay time.
func (*Client) TagAsDeleted2 ¶
TagAsDeleted2 a key, the key will expire after delay time.
type Options ¶
type Options struct { // Delay is the delay delete time for keys that are tag deleted. default is 10s Delay time.Duration // EmptyExpire is the expire time for empty result. default is 60s EmptyExpire time.Duration // LockExpire is the expire time for the lock which is allocated when updating cache. default is 3s // should be set to the max of the underling data calculating time. LockExpire time.Duration // LockSleep is the sleep interval time if try lock failed. default is 100ms LockSleep time.Duration // WaitReplicas is the number of replicas to wait for. default is 0 // if WaitReplicas is > 0, it will use redis WAIT command to wait for TagAsDeleted synchronized. WaitReplicas int // WaitReplicasTimeout is the number of replicas to wait for. default is 3000ms // if WaitReplicas is > 0, WaitReplicasTimeout is the timeout for WAIT command. WaitReplicasTimeout time.Duration // RandomExpireAdjustment is the random adjustment for the expire time. default 0.1 // if the expire time is set to 600s, and this value is set to 0.1, then the actual expire time will be 540s - 600s // solve the problem of cache avalanche. RandomExpireAdjustment float64 // CacheReadDisabled is the flag to disable read cache. default is false // when redis is down, set this flat to downgrade. DisableCacheRead bool // CacheDeleteDisabled is the flag to disable delete cache. default is false // when redis is down, set this flat to downgrade. DisableCacheDelete bool // StrongConsistency is the flag to enable strong consistency. default is false // if enabled, the Fetch result will be consistent with the db result, but performance is bad. StrongConsistency bool }
Options represents the options for rockscache client