Documentation
¶
Index ¶
- type Cache
- type InMemory
- func (c *InMemory) CheckStatus(ctx context.Context) (time.Duration, error)
- func (c *InMemory) Clear(key string)
- func (c *InMemory) Get(key string) ([]byte, bool)
- func (c *InMemory) GetCompressed(key string) (io.Reader, bool)
- func (c *InMemory) Keys(prefix string) []string
- func (c *InMemory) MultiGet(keys []string) [][]byte
- func (c *InMemory) RefreshTTL(key string, expiration time.Duration)
- func (c *InMemory) Set(key string, data []byte, expiration time.Duration)
- func (c *InMemory) SetCompressed(key string, data []byte, expiration time.Duration)
- func (c *InMemory) SetNX(key string, data []byte, expiration time.Duration)
- type Redis
- func (c *Redis) CheckStatus(ctx context.Context) (time.Duration, error)
- func (c *Redis) Clear(key string)
- func (c *Redis) Get(key string) ([]byte, bool)
- func (c *Redis) GetCompressed(key string) (io.Reader, bool)
- func (c *Redis) Keys(prefix string) []string
- func (c *Redis) MultiGet(keys []string) [][]byte
- func (c *Redis) RefreshTTL(key string, expiration time.Duration)
- func (c *Redis) Set(key string, data []byte, expiration time.Duration)
- func (c *Redis) SetCompressed(key string, data []byte, expiration time.Duration)
- func (c *Redis) SetNX(key string, data []byte, expiration time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
CheckStatus(ctx context.Context) (time.Duration, error)
Get(key string) ([]byte, bool)
MultiGet(keys []string) [][]byte
Keys(prefix string) []string
Clear(key string)
Set(key string, data []byte, expiration time.Duration)
SetNX(key string, data []byte, expiration time.Duration)
GetCompressed(key string) (io.Reader, bool)
SetCompressed(key string, data []byte, expiration time.Duration)
RefreshTTL(key string, expiration time.Duration)
}
Cache is a rudimentary key/value caching store backed by redis. It offers a Get/Set interface as well a its gzip compressed alternative GetCompressed/SetCompressed
func New ¶
func New(client redis.UniversalClient) Cache
New instantiate a Cache Client.
The backend selection is done based on the `client` argument. If a client is given, the redis backend is chosen, if nil is provided the inmemory backend would be chosen.
type InMemory ¶
type InMemory struct {
// contains filtered or unexported fields
}
InMemory implementation of the Cache client.
func NewInMemory ¶
func NewInMemory() *InMemory
NewInMemory instantiates a new in-memory Cache Client.
func (*InMemory) CheckStatus ¶
CheckStatus checks that the cache is ready, or returns an error.
func (*InMemory) Get ¶
Get fetch the cached asset at the given key, and returns true only if the asset was found.
func (*InMemory) GetCompressed ¶
GetCompressed works like Get but expect a compressed asset that is uncompressed.
func (*InMemory) RefreshTTL ¶
RefreshTTL can be used to update the TTL of an existing entry in the cache.
func (*InMemory) SetCompressed ¶
SetCompressed works like Set but compress the asset data before storing it.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis implementation of the cache client.
func NewRedis ¶
func NewRedis(client redis.UniversalClient) *Redis
NewRedis instantiate a new Redis Cache Client.
func (*Redis) CheckStatus ¶
CheckStatus checks that the cache is ready, or returns an error.
func (*Redis) Get ¶
Get fetch the cached asset at the given key, and returns true only if the asset was found.
func (*Redis) GetCompressed ¶
GetCompressed works like Get but expect a compressed asset that is uncompressed.
func (*Redis) Keys ¶
Keys returns the list of keys with the given prefix.
Note: it can be slow and should be used carefully.
func (*Redis) RefreshTTL ¶
RefreshTTL can be used to update the TTL of an existing entry in the cache.
func (*Redis) SetCompressed ¶
SetCompressed works like Set but compress the asset data before storing it.