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
- func Wrap(err, additionalErr error) error
- type Cache
- func NewBolt(db *bt.DB) Cachedeprecated
- func NewChain(drivers ...Cache) Cache
- func NewFile(dir string) Cachedeprecated
- func NewMap() Cache
- func NewMemcached(driver *memcache.Client) Cachedeprecated
- func NewMongo(collection *mgo.Collection) Cachedeprecated
- func NewRedis(driver rd.BaseCmdable) Cachedeprecated
- func NewSqlite3(db *sql.DB, table string) (Cache, error)deprecated
- func NewSyncMap() Cache
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") )
View Source
const ErrBoltBucketNotFound = err("Bucket not found")
ErrBoltBucketNotFound returns an error when bucket not found
View Source
const ErrFileOpen = err("unable to open file")
ErrFileOpen returns an error when try to open a file.
View Source
const ErrMapKeyNotFound = err("key not found")
ErrMapKeyNotFound returns an error when the key is not found.
View Source
const ErrSyncMapKeyNotFound = err("key not found")
ErrSyncMapKeyNotFound returns an error when the key is not found.
Variables ¶
This section is empty.
Functions ¶
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
func NewMemcached
deprecated
func NewRedis
deprecated
func NewRedis(driver rd.BaseCmdable) Cache
NewRedis creates an instance of Redis cache driver
Deprecated: Use redis.New instead.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.