Documentation
¶
Overview ¶
Package cache provides a cache manager for any type that implements the cache.Interface. Features: Event-Driven, statistics, prefixing and provider registration/validation.
Index ¶
Constants ¶
View Source
const ( // DefaultPrefix of the cache provider. DefaultPrefix = "" // DefaultExpiration of the cache provider. DefaultExpiration = 0 // NoExpiration for the cache item. NoExpiration = -1 )
Defaults
View Source
const (
MEMORY = "memory"
)
All predefined providers are listed here.
Variables ¶
View Source
var (
ErrNotExist = "cache: item or prefix %s does not exist"
)
Error messages.
Functions ¶
Types ¶
type Interface ¶
type Interface interface { // Get returns an Item by its name. // Error must returns if it does not exist. Get(name string) (Item, error) // All cached items. // Must returns nil if the cache is empty. All() ([]Item, error) // Set an item by its name, value and lifetime. // If cache.NoExpiration is set, the item should not get deleted. Set(name string, value interface{}, exp time.Duration) error // Delete a value by its name. // Error must return if it does not exist. Delete(name string) error // DeleteAll items. DeleteAll() error // GC will be called once as goroutine. // If the cache backend has its own garbage collector (redis, memcached, ...) just return void in this method. GC() }
Interface description for cache providers.
type Item ¶
type Item interface { Name() string Value() interface{} Created() time.Time Expiration() time.Duration }
Item interface for the cached object.
type Manager ¶
type Manager interface { Get(prefix string, name string) (Item, error) Prefix(prefix string) ([]Item, error) All() ([]Item, error) Set(prefix string, name string, value interface{}, exp time.Duration) error Exist(prefix string, name string) bool Delete(prefix string, name string) error DeletePrefix(prefix string) error DeleteAll() error HitCount(prefix string, name string) int MissCount(prefix string, name string) int SetDefaultPrefix(string) SetDefaultExpiration(duration time.Duration) }
Manager for cache operations.
func New ¶
New returns a specific cache provider by its name and given options. For the specific provider options please check out the provider details. If the provider is not registered an error will return. The provider initialization only happens once (calling the GC() function), after that a reference will return.
Click to show internal directories.
Click to hide internal directories.