Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrTimeout is timeout error ErrTimeout = errors.New("timeout") // ErrInternal should never happen ErrInternal = errors.New("internal") )
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 - an instance of the same type as the return interface{}
// 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) (interface{}, 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) (interface{}, error)
Get implements Cache interface
func (*Client) Invalidate ¶
Invalidate implements Cache interface
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.