Documentation
¶
Index ¶
- Variables
- type Cache
- func (c *Cache) ByTag(tag string, out interface{}) error
- func (c *Cache) Close() (err error)
- func (c *Cache) Del(keys ...string) error
- func (c *Cache) DelByTag(tags ...string) error
- func (c *Cache) Extend(key string, expiration time.Duration) error
- func (c *Cache) Flush() (err error)
- func (c *Cache) Get(key string, out interface{}) error
- func (c *Cache) Loop(high func(s Storage) (bool, error), medium func(s Storage) (bool, error)) (e error)
- func (c *Cache) NsKey(key string) string
- func (c *Cache) Set(key string, v interface{}, expiration time.Duration, tags ...string) error
- type Fs
- type InMem
- type Memcache
- type Option
- type Priority
- type Storage
- type Tagger
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotExist indicates that the key does not exist in the storage ErrKeyNotExist = errors.New("key does not exist") // ErrNotJSONMarshalable indicates that the content is not json marshalable ErrNotJSONMarshalable = errors.New("value is not json marshalable") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache manages to Set, Get, Delet and Tag keys
func (*Cache) Extend ¶
Extend sets the new expiration time for the given key If the expiration has not initially been set this method will add one
func (*Cache) Get ¶
Get reads for the given key from the registered storage unless a valid content is received. It will ignore any error occurred for medium level storage
func (*Cache) Loop ¶
func (c *Cache) Loop(high func(s Storage) (bool, error), medium func(s Storage) (bool, error)) (e error)
Loop iterates through registered high and medium storage and pass them to the coressponding function to use
type Fs ¶
type Fs struct {
// contains filtered or unexported fields
}
Fs is a struct implementing Storage interface using File System as data storage
func Filesystem ¶
Filesystem creates a new File System storage which can be used when creating a new cache instance cache.New(WithStorage(...))
type InMem ¶
InMem is a struct which implements Storage interface using memory as storage
func InMemory ¶
func InMemory() *InMem
InMemory creates a new in memory storage which can be passed to cache.New(WithStorage(...))
type Memcache ¶
type Memcache struct {
// contains filtered or unexported fields
}
Memcache is a structure implemening Storage interface using memcached as a storage provider
func Memcached ¶
Memcached creates a new memcached storage which can be passed to cache.New(WithStorage(...))
type Option ¶
type Option func(c *Cache)
Option is the type of constructor options for New(...).
func WithHighPriorityStorage ¶
WithHighPriorityStorage configures a cache instance with a priority cache.Storage to store data
func WithMediumPriorityStorage ¶
WithMediumPriorityStorage configures a cache instance with a medium cache.Storage to store data
func WithNamespace ¶
WithNamespace configures a cache instance with namespace.
func WithStorage ¶
WithStorage configures a cache client with a cache.Storage to store data
func WithTagger ¶
WithTagger configures a cache instance with custom cache.Tagger
type Priority ¶
type Priority int
Priority refers to the storage priority There are `high` and `medium` priorities for storage Any error occurred for high level storage will be reported Any error occurred for medium level storage will be ignored
type Storage ¶
type Storage interface { // Write writes to the storage Write(key string, v interface{}, ttl time.Duration) error // Read reads from the storage for the key Read(key string) (interface{}, error) // Delete deletes from the storage Delete(key string) error // Flush flushes cache storage Flush() error }
Storage is an interface to write, read, delete and empty a data storage. Any struct implementing Storage interface can be passed to cache.New(WithStorage(...)) to use as taggable cache data adapter
func Redis ¶
func Redis(options *redisClient.Options) Storage
type Tagger ¶
type Tagger interface { // attach tags to the given key Tag(s Storage, key string, tags ...string) error // unattach tags from the given key UnTag(s Storage, key string, tags ...string) error // receive all key's tags Tags(s Storage, key string) ([]string, error) // receive all tag's keys Keys(s Storage, tag string) ([]string, error) }
Tagger ins an interface to tag and untag data with the given tags Any struct implemening tagger interface can be passed to cache.New(WithTagger(...)) to use a data tagger