Documentation
¶
Overview ¶
Package cachego provides a simple way to use cache drivers.
Example Usage ¶
The following is a simple example using memcached driver:
import (
"fmt"
"github.com/faabiosr/cachego"
"github.com/bradfitz/gomemcache/memcache"
)
func main() {
cache := cachego.NewMemcached(
memcached.New("localhost:11211"),
)
cache.Save("foo", "bar")
fmt.Println(cache.Fetch("foo"))
}
Index ¶
Constants ¶
View Source
const ( // ErrCacheExpired returns an error when the cache key was expired. ErrCacheExpired = err("cache expired") // ErrFlush returns an error when flush fails. ErrFlush = err("unable to flush") // ErrSave returns an error when save fails. ErrSave = err("unable to save") // ErrDelete returns an error when deletion fails. ErrDelete = err("unable to delete") // ErrDecode returns an errors when decode fails. ErrDecode = err("unable to decode") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Contains check if a cached key exists
Contains(key string) bool
// Delete remove the cached key
Delete(key string) error
// Fetch retrieve the cached key value
Fetch(key string) (string, error)
// FetchMulti retrieve multiple cached keys value
FetchMulti(keys []string) map[string]string
// Flush remove all cached keys
Flush() error
// Save cache a value by key
Save(key string, value string, lifeTime time.Duration) error
}
Cache is the top-level cache interface
Click to show internal directories.
Click to hide internal directories.