Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotFound is returned when the cache // is consulted for an item which does not // exist in it. ErrNotFound = errors.New("not found") // DefaultBytesLimit is the initial capacity of // the memcache in terms of total bytes stored. // It can be set by using the MaxBytesLimit option // with a different value during initialization. DefaultBytesLimit = uint(64 * 1024 * 1024) // 64MB // DefaultItemLimit is the initial capacity of // the memcache in terms of total items stored. // It can be set by using the MaxItemLimit option // with a different value during initialization. DefaultItemLimit = uint(64 * 1024 * 4) // ~256K items )
Functions ¶
func MaxBytesLimit ¶
func MaxBytesLimit(b uint) cacheOption
MaxBytesLimit sets the maximum total size of items the cache can hold. When this limit is exceeded, the least accessed item gets deleted from the cache.
func MaxItemLimit ¶
func MaxItemLimit(l uint) cacheOption
MaxItemLimit sets the maximum number of items the cache can hold. When this limit is exceeded, the least accessed item gets deleted from the cache.
Types ¶
type Cache ¶
type Cache interface {
Fetch(key string) ([]byte, error)
Set(key string, value []byte, exp time.Duration) error
Delete(key string) error
}
Cache is the interface for basic cache impementations
type MemCache ¶
func NewMemCache ¶
func NewMemCache(opts ...cacheOption) *MemCache
NewMemCache returns an in-memory implementation of the Cache interface.
Click to show internal directories.
Click to hide internal directories.