tagcache

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

README

tagcache

import

	"github.com/weisd/tagcache"
	_ "github.com/weisd/tagcache/redis"

Documentation

	c, err := tagcache.New(tagcache.Options{Adapter: "redis", AdapterConfig: `{"Addr":"127.0.0.1:6379"}`, Section: "dada"})
	if err != nil {
		t.Fatal(err)
	}

	// base use
	err = c.Set("da", "weisd", 300)
	if err != nil {
		t.Fatal(err)
	}

	res := c.Get("da")

	if res != "weisd" {
		t.Fatal("base Set faield")
	}

	t.Log("ok")

	// use tags/namespace
	err = c.Tags([]string{"dd"}).Set("da", "weisd", 300)
	if err != nil {
		t.Fatal(err)
	}
	res = c.Tags([]string{"dd"}).Get("da")

	if res != "weisd" {
		t.Fatal("tags Set faield")
	}

	t.Log("ok")

	err = c.Tags([]string{"aa"}).Set("aa", "aaa", 300)
	if err != nil {
		t.Fatal(err)
	}

	res = c.Tags([]string{"aa"}).Get("aa")

	if res != "aaa" {
		t.Fatal("not aaa")
	}

	t.Log("ok")

	err = c.Tags([]string{"aa", "cc"}).Set("cc", "dada", 300)
	if err != nil {
		t.Fatal(err)
	}

	res = c.Tags([]string{"aa", "cc"}).Get("cc")

	if res != "dada" {
		t.Fatal("not aaa")
	}

	t.Log("ok")

	// flush namespace
	err = c.Tags([]string{"aa"}).Flush()
	if err != nil {
		t.Fatal(err)
	}

	res = c.Tags([]string{"aa"}).Get("aa")
	if res != "" {
		t.Fatal("flush faield")
	}

	res = c.Tags([]string{"aa", "cc"}).Get("cc")
	if res != "" {
		t.Fatal("flush faield")
	}

	res = c.Tags([]string{"aa"}).Get("bb")
	if res != "" {
		t.Fatal("flush faield")
	}

	// still store in
	res = c.Tags([]string{"dd"}).Get("da")
	if res != "weisd" {
		t.Fatal("where ")
	}

	t.Log("ok")

	// c.Flush()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeMD5

func EncodeMD5(str string) string

func Register

func Register(name string, adapter CacheStore)

Register registers a adapter.

func Version

func Version() string

Types

type Cache

type Cache interface {
	CacheStore
	Tags(tags []string) Cache
}

func New

func New(opt Options) (Cache, error)

func NewTagCache

func NewTagCache(store CacheStore, names ...string) Cache

type CacheStore

type CacheStore interface {
	// Set Sets value into cache with key and expire time.
	Set(key, val string, timeout int64) error
	MSet(items map[string]string, timeout int64) error
	// Get gets cached value by given key.
	Get(key string) string
	// Get Multi keys
	MGet(keys []string) []string
	// Delete deletes cached value by given key.
	Delete(key string) error
	// Incr increases cached int-type value by given key as a counter.
	Incr(key string) (int64, error)
	// Decr decreases cached int-type value by given key as a counter.
	Decr(key string) (int64, error)
	// Flush deletes all cached data.
	Flush() error
	// StartAndGC starts GC routine based on config string settings.
	StartAndGC(opt Options) error
	// update expire time
	Touch(key string, expire int64) error
}

Cache is the interface that operates the cache data.

type Engine

type Engine struct {
	Opt Options
	// contains filtered or unexported fields
}

func (*Engine) Decr

func (this *Engine) Decr(key string) (int64, error)

func (*Engine) Delete

func (this *Engine) Delete(key string) error

func (*Engine) Flush

func (this *Engine) Flush() error

func (*Engine) Get

func (this *Engine) Get(key string) string

func (*Engine) Incr

func (this *Engine) Incr(key string) (int64, error)

func (*Engine) MGet

func (this *Engine) MGet(keys []string) []string

func (*Engine) MSet

func (this *Engine) MSet(items map[string]string, timeout int64) error

func (*Engine) Set

func (this *Engine) Set(key, val string, timeout int64) error

func (*Engine) StartAndGC

func (this *Engine) StartAndGC(opt Options) error

func (*Engine) Tags

func (this *Engine) Tags(tags []string) Cache

func (*Engine) Touch

func (this *Engine) Touch(key string, expire int64) error

type Options

type Options struct {
	// Name of adapter. Default is "memory".
	Adapter string
	// Adapter configuration, it's corresponding to adapter.
	AdapterConfig string
	// key prefix Default is ""
	Section string
}

type TagCache

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

func (*TagCache) Decr

func (this *TagCache) Decr(key string) (int64, error)

func (*TagCache) Delete

func (this *TagCache) Delete(key string) error

func (*TagCache) Flush

func (this *TagCache) Flush() error

func (*TagCache) Get

func (this *TagCache) Get(key string) string

func (*TagCache) Incr

func (this *TagCache) Incr(key string) (int64, error)

func (*TagCache) MGet

func (this *TagCache) MGet(keys []string) []string

func (*TagCache) MSet

func (this *TagCache) MSet(items map[string]string, expire int64) error

func (*TagCache) Set

func (this *TagCache) Set(key, value string, expire int64) error

func (*TagCache) StartAndGC

func (this *TagCache) StartAndGC(opt Options) error

func (*TagCache) TaggedItemKey

func (this *TagCache) TaggedItemKey(key string) string

func (*TagCache) Tags

func (this *TagCache) Tags(tags []string) Cache

add Tags

func (*TagCache) Touch

func (this *TagCache) Touch(key string, expire int64) error

更新过期时间

type TagSet

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

func NewTagSet

func NewTagSet(store CacheStore, names []string) *TagSet

func (*TagSet) AddNames

func (this *TagSet) AddNames(names []string)

func (*TagSet) GetNamespace

func (this *TagSet) GetNamespace() string

取命名空间

func (*TagSet) Reset

func (this *TagSet) Reset() error

刷新所有 tag key

func (*TagSet) ResetTag

func (this *TagSet) ResetTag(name string) string

重置tagID 版本+1

func (*TagSet) SetNames

func (this *TagSet) SetNames(names []string)

func (*TagSet) TagId

func (this *TagSet) TagId(name string) string

取tag id

func (*TagSet) TagIds

func (this *TagSet) TagIds() []string

取所有的tagid

func (*TagSet) TagKey

func (this *TagSet) TagKey(name string) string

Tag key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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