persist

package
v0.0.0-...-3b02b1c Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = errors.New("persist cache miss error")

ErrCacheMiss represent the cache key does not exist in the store

Functions

func Deserialize

func Deserialize(payload []byte, ptr interface{}) (err error)

Deserialize will deserialize the passed []byte into the passed ptr interface{}

func Serialize

func Serialize(value interface{}) ([]byte, error)

Serialize returns a []byte representing the passed value

Types

type CacheStore

type CacheStore interface {
	// Get retrieves an item from the Cache. if key does not exist in the store, return ErrCacheMiss
	Get(key string, value interface{}) error

	// Set sets an item to the Cache, replacing any existing item.
	Set(key string, value interface{}, expire time.Duration) error

	// Delete removes an item from the Cache. Does nothing if the key is not in the Cache.
	Delete(key string) error
}

CacheStore is the interface of a Cache backend

type MemoryStore

type MemoryStore struct {
	Cache *ttlcache.Cache
}

MemoryStore local memory cache store

func NewMemoryStore

func NewMemoryStore(defaultExpiration time.Duration) *MemoryStore

NewMemoryStore allocate a local memory store with default expiration

func (*MemoryStore) Delete

func (c *MemoryStore) Delete(key string) error

Delete remove key in memory store, do nothing if key doesn't exist

func (*MemoryStore) Get

func (c *MemoryStore) Get(key string, value interface{}) error

Get key in memory store, if key doesn't exist, return ErrCacheMiss

func (*MemoryStore) Set

func (c *MemoryStore) Set(key string, value interface{}, expireDuration time.Duration) error

Set put key value pair to memory store, and expire after expireDuration

type RedisStore

type RedisStore struct {
	RedisClient *redis.Client
}

RedisStore store http response in redis

func NewRedisStore

func NewRedisStore(redisClient *redis.Client) *RedisStore

NewRedisStore create a redis memory store with redis client

func (*RedisStore) Delete

func (store *RedisStore) Delete(key string) error

Delete remove key in redis, do nothing if key doesn't exist

func (*RedisStore) Get

func (store *RedisStore) Get(key string, value interface{}) error

Get retrieves an item from redis, if key doesn't exist, return ErrCacheMiss

func (*RedisStore) Set

func (store *RedisStore) Set(key string, value interface{}, expire time.Duration) error

Set put key value pair to redis, and expire after expireDuration

Jump to

Keyboard shortcuts

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