cache

package
v0.0.0-...-a11d02e Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

A minimalistic cache implementation for golang using, hopefully clusterized, redis servers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoKey       = errors.New("No key")
	ErrNoConnector = errors.New("GoReCache requires Connector")
	ErrNilPointer  = errors.New("Nil pointer is not permitted")
	ErrRESPParse   = errors.New("RESP parse error")
	ErrSetFailed   = errors.New("Set operation failed by constraint")
)

Functions

This section is empty.

Types

type Cache

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

Main object for the cache

func NewCache

func NewCache(connector Connector, options *CacheOptions) (*Cache, error)

NewCache returns a Cache with given connector and options. If no options given, i.e. nil, it set them with default values.

func (*Cache) CheckAndSet

func (c *Cache) CheckAndSet(key interface{}, val interface{}, oserial int64) (int64, error)

CheckAndSet put a value with a key into the Cache, ONLY IF it has no newer values with, i.e. no update since, a given serial. It takes key, value parameters as an interface{} type and performs marshal for them. If succeed, it returns a serial number(an unix timestamp in millis) for the value. If a value of newer serial already exists, CheckAndSet would fail with ErrSetFailed.

func (*Cache) Del

func (c *Cache) Del(key interface{}) error

Del remove a cached value for the given key. It takes a key parameter as an interface{} type and performs marshal for it.

func (*Cache) Get

func (c *Cache) Get(key interface{}, val interface{}) (int64, error)

Get returns a cached value using bound Connector. It takes key, value parameters as an interface{} type and performs marshal/unmarshal for them.

func (*Cache) Hits

func (c *Cache) Hits() int64

Hits returns the cache hit counter

func (*Cache) Loads

func (c *Cache) Loads() int64

Loads return the cache load(set) counter

func (*Cache) Misses

func (c *Cache) Misses() int64

Misses return the cache miss counter

func (*Cache) Set

func (c *Cache) Set(key interface{}, val interface{}) (int64, error)

Set put a value with a key into the Cache. It takes key, value parameters as an interface{} type and performs marshal for them. If succeed, it returns a serial number(an unix timestamp in millis) for the value. If a value of newer serial already exists, Set would fail with ErrSetFailed.

type CacheOptions

type CacheOptions struct {

	// Marshaling function to serialize a key or a value for the cache
	Marshal func(interface{}) ([]byte, error)

	// Unmarshaling function to deserialize a key or a value for the cache
	Unmarshal func([]byte, interface{}) error

	// Cache expiration time
	Expiration time.Duration
}

CacheOptions describes various paramters to control cache behaviors

Jump to

Keyboard shortcuts

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