gocache

package module
v0.0.0-...-2e7882b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

README

Build Status codecov

Cache is a package which implements a unified interface for various Golang based cache.

Current drivers include:

More drivers are most welcome! Just make sure they meet at least the "cache".Cache interface and are unit tested.

Documentation

Overview

Package gocache implements a set of drivers and a common interface for working with different cache systems

Index

Constants

View Source
const (
	// ReplicateAsync indicates that replication will be done asyncronously.
	// Set commands will return without error as soon as at least one node has
	// the value
	ReplicateAsync ReplicationMethod = iota

	// ReplicateSync indicates that replication will be done syncronously.
	// Set commands will return without error only if all nodes return without error
	ReplicateSync = iota

	// RetrieveSync indicates that get commands(get, exists) will be send to one
	// node at a time starting with the closest node, and the first result will be used
	RetrieveSync RetrievalMethod = iota

	// RetrieveAsync indicates that get commands(get, exists) will be send in parallel
	// to the given nodes, and the first result will be used
	RetrieveAsync = iota
)

Variables

View Source
var (
	// ErrGetTimeout indicates a retrieval command timed out
	ErrGetTimeout = errors.New("get timeout")
	// ErrSetTimeout indicates a storage command timed out
	ErrSetTimeout = errors.New("set timeout")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Client is a cache client with built in replication to any number of different caches. This allows replication and syncronization across various caches using the set of drivers available as subpackages, including Memcached, Redis, in-memory caches, and more.

func New

func New() *Client

New returns a new initialized cache Client with no nodes.

func (*Client) AddNode

func (c *Client) AddNode(name string, node cache.Cache) error

AddNode adds a cache node with the given name, but only if it doesn't already exist

func (*Client) Del

func (c *Client) Del(key string) (err error)

Del implements the "cache.Cache".Del() interface. It deletes the given key across all replicated nodes and returns error if any of those delete operations fail.

func (*Client) Exists

func (c *Client) Exists(key string) (exists bool)

Exists implements the "cache.Cache".Exists() interface

func (*Client) Get

func (c *Client) Get(key string, dstVal interface{}) (err error)

Get implements the "cache.Cache".Get() interface. It checks nodes in order of priority, and returns success if the value exists on any of them.

func (*Client) GetTimeout

func (c *Client) GetTimeout(dur time.Duration)

GetTimeout updates the get command timeout duration

func (*Client) RemoveNode

func (c *Client) RemoveNode(name string) error

RemoveNode removes a node with the given name from the node list

func (*Client) ReplaceNode

func (c *Client) ReplaceNode(name string, node cache.Cache) error

ReplaceNode adds a cache node with the given name, but only if it already exists

func (*Client) ReplicateToN

func (c *Client) ReplicateToN(numNodes int) error

ReplicateToN sets how many nodes each key should be replicated to

func (*Client) Set

func (c *Client) Set(key string, value interface{}, exp time.Duration) (err error)

Set implements the "cache.Cache".Set() interface

func (*Client) SetNode

func (c *Client) SetNode(name string, node cache.Cache) error

SetNode sets the cache node with the given name, regardless of whether it already exists or not

func (*Client) SetReplicateMethod

func (c *Client) SetReplicateMethod(m ReplicationMethod)

SetReplicateMethod sets the replication method

func (*Client) SetRetrievalMethod

func (c *Client) SetRetrievalMethod(m RetrievalMethod)

SetRetrievalMethod sets the retrieval method

func (*Client) SetTimeout

func (c *Client) SetTimeout(dur time.Duration)

SetTimeout updates the set command timeout duration

type ReplicationMethod

type ReplicationMethod int

ReplicationMethod determines whether replication takes place asyncronously or syncronously. Use ReplicateAsync for asyncronous replication, ReplicateSync for syncronous replication.

type RetrievalMethod

type RetrievalMethod int

RetrievalMethod determines whether get commands (get, exists) are sent to all nodes simultaneously or are sent one-by-one.

Directories

Path Synopsis
Package cache defines common interfaces and error types which are implemented by drivers
Package cache defines common interfaces and error types which are implemented by drivers
Package codec implements codecs for marshaling/unmarshaling of native Go types into byte slices
Package codec implements codecs for marshaling/unmarshaling of native Go types into byte slices
drivers
appengine/memcache
Package memecache implements a cache driver for Google App Engine Go mememcache
Package memecache implements a cache driver for Google App Engine Go mememcache
bigcache
Package bigcache implements a BigCache driver for github.com/allegro/bigcache
Package bigcache implements a BigCache driver for github.com/allegro/bigcache
freecache
Package freecache implements a FreeCache driver for github.com/coocood/freecache
Package freecache implements a FreeCache driver for github.com/coocood/freecache
gocache
Package gocache is a wrapper for Patrick Mylund Nielsen's go-cache package fouund at github.com/patricknm/go-cache
Package gocache is a wrapper for Patrick Mylund Nielsen's go-cache package fouund at github.com/patricknm/go-cache
kv
Package kv is a wrapper for permanent key/value drivers at github.com/bradberger/gokv This allows using permanent key/value datastores like BoltDB, DiskV, LevelDB, etc., for persistent caching.
Package kv is a wrapper for permanent key/value drivers at github.com/bradberger/gokv This allows using permanent key/value datastores like BoltDB, DiskV, LevelDB, etc., for persistent caching.
lru
Package lru implements a least recently used in-memory cache.
Package lru implements a least recently used in-memory cache.
memcache
Package memcache implements a memcache driver for github.com/bradfitz/gomemcache/memcache
Package memcache implements a memcache driver for github.com/bradfitz/gomemcache/memcache
memory
Package memory implements a very basic, fully functional cache.Cache interface with in-memory caching and key expiration.
Package memory implements a very basic, fully functional cache.Cache interface with in-memory caching and key expiration.
radix
Package radix implements a driver for github.com/armon/go-radix
Package radix implements a driver for github.com/armon/go-radix
redis
Package redis implements a driver for github.com/garyburd/redigo/redis
Package redis implements a driver for github.com/garyburd/redigo/redis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL