hashed

package
v0.0.0-...-2c17daf Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: MIT, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Key     string
	Expired int64
	Data    []byte
}

Data cache data struct

func NewData

func NewData(key string, expired int64, data []byte) *Data

NewData create new data with given key,expiired time stamp and data

type Driver

type Driver struct {
	cache.DriverUtil
	Store        Store
	GcErrHanlder func(err error)
}

Driver driver struct

func NewDriver

func NewDriver(Store Store) *Driver

NewDriver create new cache driver with given store

func (*Driver) Close

func (d *Driver) Close() error

Close close cache.

func (*Driver) Del

func (d *Driver) Del(key string) error

Del Delete data in cache by given key.

func (*Driver) DelCounter

func (d *Driver) DelCounter(key string) error

DelCounter Delete int val in cache by given key.Count cache and data cache are in two independent namespace.

func (*Driver) Expire

func (d *Driver) Expire(key string, ttl time.Duration) error

Expire set item ttl by given key and ttl.

func (*Driver) ExpireCounter

func (d *Driver) ExpireCounter(key string, ttl time.Duration) error

ExpireCounter set int item ttl by given key and ttl.

func (*Driver) Flush

func (d *Driver) Flush() error

Flush Delete all data in cache.

func (*Driver) GetBytesValue

func (d *Driver) GetBytesValue(key string) ([]byte, error)

GetBytesValue Get bytes data from cache by given key.

func (*Driver) GetCounter

func (d *Driver) GetCounter(key string) (int64, error)

GetCounter Get int val from cache by given key.Count cache and data cache are in two independent namespace.

func (*Driver) IncrCounter

func (d *Driver) IncrCounter(key string, increment int64, ttl time.Duration) (int64, error)

IncrCounter Increase int val in cache by given key.Count cache and data cache are in two independent namespace.

func (*Driver) MGetBytesValue

func (d *Driver) MGetBytesValue(keys ...string) (map[string][]byte, error)

MGetBytesValue get multiple bytes data from cache by given keys. Return data bytes map and any error if raised.

func (*Driver) MSetBytesValue

func (d *Driver) MSetBytesValue(data map[string][]byte, ttl time.Duration) error

MSetBytesValue set multiple bytes data to cache with given key-value map. Return any error if raised.

func (*Driver) SetBytesValue

func (d *Driver) SetBytesValue(key string, bytes []byte, ttl time.Duration) error

SetBytesValue Set bytes data to cache by given key.

func (*Driver) SetCounter

func (d *Driver) SetCounter(key string, v int64, ttl time.Duration) error

SetCounter Set int val in cache by given key.Count cache and data cache are in two independent namespace.

func (*Driver) SetGCErrHandler

func (d *Driver) SetGCErrHandler(f func(err error))

SetGCErrHandler Set callback to handler error raised when gc.

func (*Driver) UpdateBytesValue

func (d *Driver) UpdateBytesValue(key string, bytes []byte, ttl time.Duration) error

UpdateBytesValue Update bytes data to cache by given key only if the cache exist.

type Hashed

type Hashed []*Data

Hashed cache hashed data.

func New

func New() *Hashed

New create new cache hashed data.

type Status

type Status struct {
	FirstExpired int64
	LastExpired  int64
	Size         int
	Delta        int
	Changed      bool
}

Status hash data status

func NewStatus

func NewStatus() *Status

NewStatus create new status

type Store

type Store interface {
	//Close close cache store.
	//Return any error if raised.
	Close() error
	//Flush flush cache.
	//Return any error if raised.
	Flush() error
	//Hash hash given key to hashed string.
	//Return hash and any error if raised
	Hash(string) (string, error)
	//Lock lock by given hashed key.
	//Return unlock func and any error if raised
	Lock(string) (func(), error)
	//Load load hash data by given hash key.
	//Return hash data and any error if raised.
	Load(hash string) (*Hashed, error)
	//Delete delete all data by given hash key.
	//Return any error if raised.
	Delete(hash string) error
	//Save save hash data by given hash key,status and hash data.
	//Return any error if raised.
	Save(hash string, status *Status, data *Hashed) error
}

Store cache store interface

Jump to

Keyboard shortcuts

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