Documentation
¶
Index ¶
- Variables
- func SetNowFunc(f func() time.Time)
- type Cache
- type CacheDuration
- type Client
- func (c *Client) Close()
- func (c *Client) Get(ctx context.Context, queryKey QueryKey, target interface{}, ...) error
- func (c *Client) GetWithExpire(ctx context.Context, queryKey QueryKey, target interface{}, ...) error
- func (c *Client) Invalidate(ctx context.Context, key QueryKey) error
- func (c *Client) Set(ctx context.Context, key QueryKey, val interface{}, ttl time.Duration) error
- type PassThroughExpireFunc
- type PassThroughFunc
- type QueryKey
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SetNowFunc ¶
SetNowFunc is a helper function to replace time.Now()
Types ¶
type Cache ¶
type Cache interface { // Get returns value of f while caching in redis and inmemcache // Inputs: // queryKey - key used in cache // target - receive the cached value, must be pointer // expire - expiration of cache key // f - actual call that hits underlying data source // noCache - whether force read from data source Get(ctx context.Context, queryKey QueryKey, target interface{}, expire time.Duration, f PassThroughFunc, noCache bool) error // GetWithExpire returns value of f while caching in redis // Inputs: // queryKey - key used in cache // target - receive the cached value, must be pointer // f - actual call that hits underlying data source, sets expire duration // noCache - whether force read from data source GetWithExpire(ctx context.Context, queryKey string, target interface{}, f PassThroughExpireFunc, noCache bool) error // Set explicitly set a cache key to a val // Inputs: // key - key to set // val - val to set // ttl - ttl of key Set(ctx context.Context, key QueryKey, val interface{}, ttl time.Duration) error // Invalidate explicitly invalidates a cache key // Inputs: // key - key to invalidate Invalidate(ctx context.Context, key QueryKey) error // Close closes resources used by cache Close() }
Cache defines interface to cache
type CacheDuration ¶
const ( SuperFast CacheDuration = CacheDuration(time.Second) VeryFast CacheDuration = CacheDuration(time.Second * 2) Fast CacheDuration = CacheDuration(time.Second * 5) Normal CacheDuration = CacheDuration(time.Second * 10) Slow CacheDuration = CacheDuration(time.Second * 30) VerySlow CacheDuration = CacheDuration(time.Minute * 1) SuperSlow CacheDuration = CacheDuration(time.Minute * 5) SuperDuperSlow CacheDuration = CacheDuration(time.Hour * 1) SuperSuperDuperSlow CacheDuration = CacheDuration(time.Hour * 5) NeverExpire CacheDuration = CacheDuration(0) )
func (CacheDuration) ToDuration ¶
func (c CacheDuration) ToDuration() time.Duration
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client captures redis connection
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, queryKey QueryKey, target interface{}, expire time.Duration, f PassThroughFunc, noCache bool) error
Get implements Cache interface
func (*Client) GetWithExpire ¶
func (c *Client) GetWithExpire(ctx context.Context, queryKey QueryKey, target interface{}, f PassThroughExpireFunc, noCache bool) error
GetWithExpire implements Cache interface
func (*Client) Invalidate ¶
Invalidate implements Cache interface
type PassThroughExpireFunc ¶
PassThroughExpireFunc is the actual call to underlying data source while returning a duration as expire timer
type PassThroughFunc ¶
type PassThroughFunc = func() (interface{}, error)
PassThroughFunc is the actual call to underlying data source
Click to show internal directories.
Click to hide internal directories.