Documentation ¶
Overview ¶
Package cachey provides a simple and flexible way to cache the results of functions using either redis or memory as the backend.
Package cachey provides a simple and flexible way to cache the results of functions using either redis or memory as the backend.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a cachey client that can use either redis or memory as the cache backend.
func New ¶
func New(rc *redis.Client, cc *cache.Cache) *Client
New creates a new cachey client with the given redis and memory clients.
func (*Client) EnableDebug ¶ added in v1.0.2
EnableDebug enable debugging more detailed message with zerolog.
type ClientType ¶
type ClientType uint8
ClientType represents the type of cache backend to use for a request.
const ( RedisClient ClientType = iota // Use redis as the cache backend MemoryClient // Use memory as the cache backend )
type Func ¶
type Func func(args ...interface{}) (interface{}, error)
Func represents a function whose result can be cached by cachey.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents a cachey request that can execute a function and cache its result using either redis or memory as the cache backend.
func (*Request) Execute ¶
Execute executes this request by first trying to get the result from the cache with the given key. If it fails, it executes the function and caches its result with the given key and expiration time. It returns the result and an error if any.
func (*Request) SetCacheKey ¶
SetCacheKey sets the cache key for this request and returns itself for chaining.
func (*Request) SetExpiration ¶
SetExpiration sets the expiration time for caching the result of this request and returns itself for chaining.
func (*Request) SetFunc ¶
SetFunc sets the function to execute and cache its result for this request and returns itself for chaining.
func (*Request) SetResultType ¶
SetResultType sets the type of result expected from the function execution for this request and returns itself for chaining.