cachego: github.com/faabiosr/cachego Index | Files

package cachego

import "github.com/faabiosr/cachego"

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

Package Files

bolt.go cache.go chain.go doc.go file.go map.go memcached.go mongo.go redis.go sqlite3.go sync_map.go

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"
)

type Bolt Uses

type Bolt struct {
    // contains filtered or unexported fields
}

Bolt store for caching data

func NewBolt Uses

func NewBolt(db *bolt.DB) *Bolt

NewBolt creates an instance of BoltDB cache

func (*Bolt) Contains Uses

func (b *Bolt) Contains(key string) bool

Contains checks if the cached key exists into the BoltDB storage

func (*Bolt) Delete Uses

func (b *Bolt) Delete(key string) error

Delete the cached key from BoltDB storage

func (*Bolt) Fetch Uses

func (b *Bolt) Fetch(key string) (string, error)

Fetch retrieves the cached value from key of the BoltDB storage

func (*Bolt) FetchMulti Uses

func (b *Bolt) FetchMulti(keys []string) map[string]string

FetchMulti retrieve multiple cached values from keys of the BoltDB storage

func (*Bolt) Flush Uses

func (b *Bolt) Flush() error

Flush removes all cached keys of the BoltDB storage

func (*Bolt) Save Uses

func (b *Bolt) Save(key string, value string, lifeTime time.Duration) error

Save a value in BoltDB storage by key

type BoltContent Uses

type BoltContent struct {
    Duration int64  `json:"duration"`
    Data     string `json:"data, omitempty"`
}

BoltContent it's a structure of cached value

type Cache Uses

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 Uses

type Chain struct {
    // contains filtered or unexported fields
}

Chain storage for dealing with multiple cache storage in the same time

func NewChain Uses

func NewChain(drivers ...Cache) *Chain

NewChain creates an instance of Chain cache driver

func (*Chain) Contains Uses

func (c *Chain) Contains(key string) bool

Contains checks if the cached key exists in one of the cache storages

func (*Chain) Delete Uses

func (c *Chain) Delete(key string) error

Delete the cached key in all cache storages

func (*Chain) Fetch Uses

func (c *Chain) Fetch(key string) (string, error)

Fetch retrieves the value of one of the registred cache storages

func (*Chain) FetchMulti Uses

func (c *Chain) FetchMulti(keys []string) map[string]string

FetchMulti retrieves multiple cached values from one of the registred cache storages

func (*Chain) Flush Uses

func (c *Chain) Flush() error

Flush removes all cached keys of the registered cache storages

func (*Chain) Save Uses

func (c *Chain) Save(key string, value string, lifeTime time.Duration) error

Save a value in all cache storages by key

type File Uses

type File struct {
    // contains filtered or unexported fields
}

File store for caching data

func NewFile Uses

func NewFile(dir string) *File

NewFile creates an instance of File cache

func (*File) Contains Uses

func (f *File) Contains(key string) bool

Contains checks if the cached key exists into the File storage

func (*File) Delete Uses

func (f *File) Delete(key string) error

Delete the cached key from File storage

func (*File) Fetch Uses

func (f *File) Fetch(key string) (string, error)

Fetch retrieves the cached value from key of the File storage

func (*File) FetchMulti Uses

func (f *File) FetchMulti(keys []string) map[string]string

FetchMulti retrieve multiple cached values from keys of the File storage

func (*File) Flush Uses

func (f *File) Flush() error

Flush removes all cached keys of the File storage

func (*File) Save Uses

func (f *File) Save(key string, value string, lifeTime time.Duration) error

Save a value in File storage by key

type FileContent Uses

type FileContent struct {
    Duration int64  `json:"duration"`
    Data     string `json:"data, omitempty"`
}

FileContent it's a structure of cached value

type Map Uses

type Map struct {
    // contains filtered or unexported fields
}

Map store the data in memory without external server

func NewMap Uses

func NewMap() *Map

NewMap creates an instance of Map cache driver

func (*Map) Contains Uses

func (m *Map) Contains(key string) bool

Contains checks if cached key exists in Map storage

func (*Map) Delete Uses

func (m *Map) Delete(key string) error

Delete the cached key from Map storage

func (*Map) Fetch Uses

func (m *Map) Fetch(key string) (string, error)

Fetch retrieves the cached value from key of the Map storage

func (*Map) FetchMulti Uses

func (m *Map) FetchMulti(keys []string) map[string]string

FetchMulti retrieves multiple cached value from keys of the Map storage

func (*Map) Flush Uses

func (m *Map) Flush() error

Flush removes all cached keys of the Map storage

func (*Map) Save Uses

func (m *Map) Save(key string, value string, lifeTime time.Duration) error

Save a value in Map storage by key

type MapItem Uses

type MapItem struct {
    // contains filtered or unexported fields
}

MapItem structure for managing data and lifetime

type Memcached Uses

type Memcached struct {
    // contains filtered or unexported fields
}

Memcached it's a wrap around the memcached driver

func NewMemcached Uses

func NewMemcached(driver *memcache.Client) *Memcached

NewMemcached creates an instance of Memcached cache driver

func (*Memcached) Contains Uses

func (m *Memcached) Contains(key string) bool

Contains checks if cached key exists in Memcached storage

func (*Memcached) Delete Uses

func (m *Memcached) Delete(key string) error

Delete the cached key from Memcached storage

func (*Memcached) Fetch Uses

func (m *Memcached) Fetch(key string) (string, error)

Fetch retrieves the cached value from key of the Memcached storage

func (*Memcached) FetchMulti Uses

func (m *Memcached) FetchMulti(keys []string) map[string]string

FetchMulti retrieves multiple cached value from keys of the Memcached storage

func (*Memcached) Flush Uses

func (m *Memcached) Flush() error

Flush removes all cached keys of the Memcached storage

func (*Memcached) Save Uses

func (m *Memcached) Save(key string, value string, lifeTime time.Duration) error

Save a value in Memcached storage by key

type Mongo Uses

type Mongo struct {
    // contains filtered or unexported fields
}

Mongo it's a wrap around the mgo driver

func NewMongo Uses

func NewMongo(collection *mgo.Collection) *Mongo

NewMongo creates an instance of Mongo cache driver

func (*Mongo) Contains Uses

func (m *Mongo) Contains(key string) bool

Contains checks if cached key exists in Mongo storage

func (*Mongo) Delete Uses

func (m *Mongo) Delete(key string) error

Delete the cached key from Mongo storage

func (*Mongo) Fetch Uses

func (m *Mongo) Fetch(key string) (string, error)

Fetch retrieves the cached value from key of the Mongo storage

func (*Mongo) FetchMulti Uses

func (m *Mongo) FetchMulti(keys []string) map[string]string

FetchMulti retrieves multiple cached value from keys of the Mongo storage

func (*Mongo) Flush Uses

func (m *Mongo) Flush() error

Flush removes all cached keys of the Mongo storage

func (*Mongo) Save Uses

func (m *Mongo) Save(key string, value string, lifeTime time.Duration) error

Save a value in Mongo storage by key

type MongoContent Uses

type MongoContent struct {
    Duration int64
    Key      string `bson:"_id"`
    Value    string
}

MongoContent it's a bson structure of cached value

type Redis Uses

type Redis struct {
    // contains filtered or unexported fields
}

Redis it's a wrap around the redis driver

func NewRedis Uses

func NewRedis(driver *redis.Client) *Redis

NewRedis creates an instance of Redis cache driver

func (*Redis) Contains Uses

func (r *Redis) Contains(key string) bool

Contains checks if cached key exists in Redis storage

func (*Redis) Delete Uses

func (r *Redis) Delete(key string) error

Delete the cached key from Redis storage

func (*Redis) Fetch Uses

func (r *Redis) Fetch(key string) (string, error)

Fetch retrieves the cached value from key of the Redis storage

func (*Redis) FetchMulti Uses

func (r *Redis) FetchMulti(keys []string) map[string]string

FetchMulti retrieves multiple cached value from keys of the Redis storage

func (*Redis) Flush Uses

func (r *Redis) Flush() error

Flush removes all cached keys of the Redis storage

func (*Redis) Save Uses

func (r *Redis) Save(key string, value string, lifeTime time.Duration) error

Save a value in Redis storage by key

type Sqlite3 Uses

type Sqlite3 struct {
    // contains filtered or unexported fields
}

Sqlite3 it's a wrap around the sqlite3 driver

func NewSqlite3 Uses

func NewSqlite3(db *sql.DB, table string) (*Sqlite3, error)

NewSqlite3 creates an instance of Sqlite3 cache driver

func (*Sqlite3) Contains Uses

func (s *Sqlite3) Contains(key string) bool

Contains checks if cached key exists in Sqlite3 storage

func (*Sqlite3) Delete Uses

func (s *Sqlite3) Delete(key string) error

Delete the cached key from Sqlite3 storage

func (*Sqlite3) Fetch Uses

func (s *Sqlite3) Fetch(key string) (string, error)

Fetch retrieves the cached value from key of the Sqlite3 storage

func (*Sqlite3) FetchMulti Uses

func (s *Sqlite3) FetchMulti(keys []string) map[string]string

FetchMulti retrieves multiple cached value from keys of the Sqlite3 storage

func (*Sqlite3) Flush Uses

func (s *Sqlite3) Flush() error

Flush removes all cached keys of the Sqlite3 storage

func (*Sqlite3) Save Uses

func (s *Sqlite3) Save(key string, value string, lifeTime time.Duration) error

Save a value in Sqlite3 storage by key

type SyncMap Uses

type SyncMap struct {
    // contains filtered or unexported fields
}

SyncMap store the data in memory without external server

func NewSyncMap Uses

func NewSyncMap() *SyncMap

NewSyncMap creates an instance of SyncMap cache driver

func (*SyncMap) Contains Uses

func (sm *SyncMap) Contains(key string) bool

Contains checks if cached key exists in SyncMap storage

func (*SyncMap) Delete Uses

func (sm *SyncMap) Delete(key string) error

Delete the cached key from SyncMap storage

func (*SyncMap) Fetch Uses

func (sm *SyncMap) Fetch(key string) (string, error)

Fetch retrieves the cached value from key of the SyncMap storage

func (*SyncMap) FetchMulti Uses

func (sm *SyncMap) FetchMulti(keys []string) map[string]string

FetchMulti retrieves multiple cached value from keys of the SyncMap storage

func (*SyncMap) Flush Uses

func (sm *SyncMap) Flush() error

Flush removes all cached keys of the SyncMap storage

func (*SyncMap) Save Uses

func (sm *SyncMap) Save(key string, value string, lifeTime time.Duration) error

Save a value in SyncMap storage by key

type SyncMapItem Uses

type SyncMapItem struct {
    // contains filtered or unexported fields
}

SyncMapItem structure for managing data and lifetime

Package cachego imports 18 packages (graph). Updated 2019-05-09. Refresh now. Tools for package owners.