cachex

package module
v0.0.0-...-ed8e7a5 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

cachex

GitHub Action Status Build status Go Report Card GoDoc Coverage Status license

snappy example

var (
	c    *Cache
	once sync.Once
)

func init() {
	once.Do(func() {
		c = NewCache(102400)
	})
}
func main() {
	src := []byte(`{"test":"test"}`)
	encoded := snappy.Encode(nil, src)
	key := ("hello")
	err := c.Set(key, encoded)
	if err != nil {
		log.Fatal(err)
	}
	_, err = c.Get(key)
	if err != nil {
		log.Fatal(err)
	}
	decoded, err := snappy.Decode(nil, encoded)
	if err != nil {
		log.Fatal(err)
	}
	valueStr := unsafe.Pointer(&decoded)
	fmt.Println(*(*string)(valueStr), key)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Mu        sync.RWMutex
	TTL       uint
	CacheLen  uint
	Cache     map[interface{}]*list.Element
	CacheList *list.List
}

Cache struct

func NewCache

func NewCache(cacheLen, ttl uint) *Cache

NewCache Cache input cacheLen uint return *Cache

func (*Cache) Get

func (c *Cache) Get(key string) ([]byte, error)

Get Cache input key string return []byte,error

func (*Cache) Set

func (c *Cache) Set(key string, value []byte) error

Set Cache input key string,value []byte return error

type Cachex

type Cachex interface {
	Set(key string, value []byte)
	Get(key string) ([]byte, error)
}

Cachex interface

type CheckExpireCallback

type CheckExpireCallback func(key string, value []byte)

CheckExpireCallback -> Check Expire CallBack Notice

type ExpireCallBackNotice

type ExpireCallBackNotice func(key string, value []byte) bool

ExpireCallBackNotice -> Expire CallBack Notice

Jump to

Keyboard shortcuts

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