cache

package
v0.0.0-...-265e4bb Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2016 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// TTL codes
	KeyTTLErrCode   = -3
	KeyNotExistCode = -2
	KeyHasNoTTLCode = -1

	// cache types
	STRING_CACHE CacheType = iota + 1
	LIST_CACHE
	DIC_CACHE
)

Variables

View Source
var (

	// prepare byte slices for common ttl responses
	TtlKeyCodes = map[int][]byte{
		KeyTTLErrCode:   []byte("-3"),
		KeyNotExistCode: []byte("-2"),
		KeyHasNoTTLCode: []byte("-1"),
	}
)

Functions

func CacheTimeNow

func CacheTimeNow() int64

func DDEL

func DDEL(key []byte) bool

DDEL removes Dic by key returns false if not exists or expired

func DEL

func DEL(key []byte) bool

DEL removes element by key

func DFDEL

func DFDEL(key, fld []byte) bool

DFDEL removes fiedl from Dic by key false if not exists or expired

func DFGET

func DFGET(key, fld []byte) ([]byte, bool)

DFGET returns field value from Dic defined by key or nil, false if not exist

func DFSET

func DFSET(key, fld, val []byte, ttl int) bool

DFSET add field and val to Dic, if not exists it initialize and add to cache

func DGET

func DGET(key []byte) (map[string][]byte, bool)

DGET returns map[string][]byte of values in Dic by key, nil, false if not exists or expired

func DKEYS

func DKEYS() []string

DKEYS returns []string of all keys of Dics cached

func DLEN

func DLEN() int

DLEN returns number of Dic cached

func DTTL

func DTTL(key []byte) int

DTTL returns ttl in seconds of key of ttl codes

func GET

func GET(key []byte) ([]byte, bool)

GET the value of a key, returns []byte, true or nil, false if expired or not exist

func Init

func Init()

func KEYS

func KEYS() []string

KEYS returns []string of all not expired keys of stored strings

func LDEL

func LDEL(key []byte) bool

LDEL removes list element by key

func LEN

func LEN() int

LEN returns number of not expired keys of stored strings

func LGET

func LGET(key []byte) ([][]byte, bool)

LGET returns [][]byte of values stored in List by a key, return nil, false if not exists or key is nil

func LKEYS

func LKEYS() []string

LKEYS returns []string of all not expired keys

func LLEN

func LLEN() int

LLEN returns number of not expired cached lists

func LPOP

func LPOP(key []byte) ([]byte, bool)

LPOP returns and removes first element in list if it was last element, list item deleted from cache returns nil, false if not exist

func LPUSH

func LPUSH(key, val []byte, ttl int) bool

LPUSH create List item in cache if not exists with ttl and prepends element to a list

func LTTL

func LTTL(key []byte) int

LTTL returns ttl of key or ttl codes

func SET

func SET(key, val []byte, ttl int) bool

SET the key with value and ttl ttl 0 means no expire returns false if key, val is nil

func TTL

func TTL(key []byte) int

TTL returns ttl in seconds of key of ttl codes

Types

type Atomic

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

func (*Atomic) Get

func (a *Atomic) Get() int64

func (*Atomic) Set

func (a *Atomic) Set(val int64)

func (*Atomic) SetSysTS

func (a *Atomic) SetSysTS()

type CacheType

type CacheType int

type Dic

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

Dic cache item struct

func NewDic

func NewDic(fld, val []byte, ttl int) Dic

NewDic initialize Dic creates map and sets first field and val

func (*Dic) FormatTTL

func (it *Dic) FormatTTL(in time.Duration) int

func (Dic) IsExpired

func (it Dic) IsExpired() bool

func (*Dic) SetTTL

func (it *Dic) SetTTL(ttl int)

type DicCache

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

DicCache is bucket holding list of caches in stripped map

type List

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

List cache item struct

func NewList

func NewList(val []byte, ttl int) List

NewList initialize List creates list and sets first element value to val and sets ttl

func (*List) FormatTTL

func (it *List) FormatTTL(in time.Duration) int

func (List) IsExpired

func (it List) IsExpired() bool

func (*List) SetTTL

func (it *List) SetTTL(ttl int)

type ListCache

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

ListCache is bucket holding list caches in stripped map

type String

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

String cache item struct

func (*String) FormatTTL

func (it *String) FormatTTL(in time.Duration) int

func (String) IsExpired

func (it String) IsExpired() bool

func (*String) SetTTL

func (it *String) SetTTL(ttl int)

type StringCache

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

StringCache is bucket holding string caches in stripped map

Jump to

Keyboard shortcuts

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