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 ¶
- Variables
- type Bolt
- type BoltContent
- type Cache
- type Chain
- type File
- type FileContent
- type Map
- type MapItem
- type Memcached
- func (m *Memcached) Contains(key string) bool
- func (m *Memcached) Delete(key string) error
- func (m *Memcached) Fetch(key string) (string, error)
- func (m *Memcached) FetchMulti(keys []string) map[string]string
- func (m *Memcached) Flush() error
- func (m *Memcached) Save(key string, value string, lifeTime time.Duration) error
- type Mongo
- type MongoContent
- type Redis
- type Sqlite3
- func (s *Sqlite3) Contains(key string) bool
- func (s *Sqlite3) Delete(key string) error
- func (s *Sqlite3) Fetch(key string) (string, error)
- func (s *Sqlite3) FetchMulti(keys []string) map[string]string
- func (s *Sqlite3) Flush() error
- func (s *Sqlite3) Save(key string, value string, lifeTime time.Duration) error
- type SyncMap
- func (sm *SyncMap) Contains(key string) bool
- func (sm *SyncMap) Delete(key string) error
- func (sm *SyncMap) Fetch(key string) (string, error)
- func (sm *SyncMap) FetchMulti(keys []string) map[string]string
- func (sm *SyncMap) Flush() error
- func (sm *SyncMap) Save(key string, value string, lifeTime time.Duration) error
- type SyncMapItem
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBoltBucketNotFound returns an error when bucket not found ErrBoltBucketNotFound = errors.New("Bucket not found") // ErrBoltCacheExpired returns an error when the cache key was expired ErrBoltCacheExpired = errors.New("Cache expired") // ErrBoltDecodeJSON returns json decoding error message ErrBoltDecodeJSON = "Unable to decode json data" // ErrBoltFlush returns flush error message ErrBoltFlush = "Unable to flush" // ErrBoltSave returns save error message ErrBoltSave = "Unable to save" )
Functions ¶
This section is empty.
Types ¶
type Bolt ¶
type Bolt struct {
// contains filtered or unexported fields
}
Bolt store for caching data
func (*Bolt) FetchMulti ¶
FetchMulti retrieve multiple cached values from keys of the BoltDB storage
type BoltContent ¶
BoltContent it's a structure of cached value
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
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain storage for dealing with multiple cache storage in the same time
func (*Chain) FetchMulti ¶
FetchMulti retrieves multiple cached values from one of the registred cache storages
type File ¶
type File struct {
// contains filtered or unexported fields
}
File store for caching data
func (*File) FetchMulti ¶
FetchMulti retrieve multiple cached values from keys of the File storage
type FileContent ¶
FileContent it's a structure of cached value
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map store the data in memory without external server
func (*Map) FetchMulti ¶
FetchMulti retrieves multiple cached value from keys of the Map storage
type MapItem ¶
type MapItem struct {
// contains filtered or unexported fields
}
MapItem structure for managing data and lifetime
type Memcached ¶
type Memcached struct {
// contains filtered or unexported fields
}
Memcached it's a wrap around the memcached driver
func NewMemcached ¶
NewMemcached creates an instance of Memcached cache driver
func (*Memcached) FetchMulti ¶
FetchMulti retrieves multiple cached value from keys of the Memcached storage
type Mongo ¶
type Mongo struct {
// contains filtered or unexported fields
}
Mongo it's a wrap around the mgo driver
func NewMongo ¶
func NewMongo(collection *mgo.Collection) *Mongo
NewMongo creates an instance of Mongo cache driver
func (*Mongo) FetchMulti ¶
FetchMulti retrieves multiple cached value from keys of the Mongo storage
type MongoContent ¶
MongoContent it's a bson structure of cached value
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis it's a wrap around the redis driver
func NewRedis ¶
func NewRedis(driver redis.BaseCmdable) *Redis
NewRedis creates an instance of Redis cache driver
func (*Redis) FetchMulti ¶
FetchMulti retrieves multiple cached value from keys of the Redis storage
type Sqlite3 ¶
type Sqlite3 struct {
// contains filtered or unexported fields
}
Sqlite3 it's a wrap around the sqlite3 driver
func NewSqlite3 ¶
NewSqlite3 creates an instance of Sqlite3 cache driver
func (*Sqlite3) FetchMulti ¶
FetchMulti retrieves multiple cached value from keys of the Sqlite3 storage
type SyncMap ¶
type SyncMap struct {
// contains filtered or unexported fields
}
SyncMap store the data in memory without external server
func (*SyncMap) FetchMulti ¶
FetchMulti retrieves multiple cached value from keys of the SyncMap storage
type SyncMapItem ¶
type SyncMapItem struct {
// contains filtered or unexported fields
}
SyncMapItem structure for managing data and lifetime