persistence

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: BSD-3-Clause, MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DEFAULT = time.Duration(0)
	FOREVER = time.Duration(-1)
)

Variables

View Source
var (
	PageCachePrefix = "gincontrib.page.cache"
	ErrCacheMiss    = errors.New("cache: key not found.")
	ErrNotStored    = errors.New("cache: not stored.")
	ErrNotSupport   = errors.New("cache: not support.")
)
View Source
var (
	ErrCacheNoTTL = errors.New("cache: key has no TTL.")
)

Functions

This section is empty.

Types

type CacheStore

type CacheStore interface {
	// Get retrieves an item from the cache. Returns the item or nil, and a bool indicating
	// whether the key was found.
	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

	// Add adds an item to the cache only if an item doesn't already exist for the given
	// key, or if the existing item has expired. Returns an error otherwise.
	Add(key string, value interface{}, expire time.Duration) error

	// Replace sets a new value for the cache key only if it already exists. Returns an
	// error if it does not.
	Replace(key string, data 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

	// Increment increments a real number, and returns error if the value is not real
	Increment(key string, data uint64) (uint64, error)

	// Decrement decrements a real number, and returns error if the value is not real
	Decrement(key string, data uint64) (uint64, error)

	// Flush seletes all items from the cache.
	Flush() error
}

CacheStore is the interface of a cache backend

type InMemoryStore

type InMemoryStore struct {
	cache.Cache
}

InMemoryStore represents the cache with memory persistence

func NewInMemoryStore

func NewInMemoryStore(defaultExpiration time.Duration) *InMemoryStore

NewInMemoryStore returns a InMemoryStore

func (*InMemoryStore) Add

func (c *InMemoryStore) Add(key string, value interface{}, expires time.Duration) error

Add (see CacheStore interface)

func (*InMemoryStore) Decrement

func (c *InMemoryStore) Decrement(key string, n uint64) (uint64, error)

Decrement (see CacheStore interface)

func (*InMemoryStore) Delete

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

Delete (see CacheStore interface)

func (*InMemoryStore) Flush

func (c *InMemoryStore) Flush() error

Flush (see CacheStore interface)

func (*InMemoryStore) Get

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

Get (see CacheStore interface)

func (*InMemoryStore) Increment

func (c *InMemoryStore) Increment(key string, n uint64) (uint64, error)

Increment (see CacheStore interface)

func (*InMemoryStore) Replace

func (c *InMemoryStore) Replace(key string, value interface{}, expires time.Duration) error

Replace (see CacheStore interface)

func (*InMemoryStore) Set

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

Set (see CacheStore interface)

type MemcachedBinaryStore

type MemcachedBinaryStore struct {
	*mc.Client
	// contains filtered or unexported fields
}

MemcachedBinaryStore represents the cache with memcached persistence using the binary protocol

func NewMemcachedBinaryStore

func NewMemcachedBinaryStore(hostList, username, password string, defaultExpiration time.Duration) *MemcachedBinaryStore

NewMemcachedBinaryStore returns a MemcachedBinaryStore

func NewMemcachedBinaryStoreWithConfig

func NewMemcachedBinaryStoreWithConfig(hostList, username, password string, defaultExpiration time.Duration, config *mc.Config) *MemcachedBinaryStore

NewMemcachedBinaryStoreWithConfig returns a MemcachedBinaryStore using the provided configuration

func (*MemcachedBinaryStore) Add

func (s *MemcachedBinaryStore) Add(key string, value interface{}, expires time.Duration) error

Add (see CacheStore interface)

func (*MemcachedBinaryStore) Decrement

func (s *MemcachedBinaryStore) Decrement(key string, delta uint64) (uint64, error)

Decrement (see CacheStore interface)

func (*MemcachedBinaryStore) Delete

func (s *MemcachedBinaryStore) Delete(key string) error

Delete (see CacheStore interface)

func (*MemcachedBinaryStore) Flush

func (s *MemcachedBinaryStore) Flush() error

Flush (see CacheStore interface)

func (*MemcachedBinaryStore) Get

func (s *MemcachedBinaryStore) Get(key string, value interface{}) error

Get (see CacheStore interface)

func (*MemcachedBinaryStore) Increment

func (s *MemcachedBinaryStore) Increment(key string, delta uint64) (uint64, error)

Increment (see CacheStore interface)

func (*MemcachedBinaryStore) Replace

func (s *MemcachedBinaryStore) Replace(key string, value interface{}, expires time.Duration) error

Replace (see CacheStore interface)

func (*MemcachedBinaryStore) Set

func (s *MemcachedBinaryStore) Set(key string, value interface{}, expires time.Duration) error

Set (see CacheStore interface)

type MemcachedStore

type MemcachedStore struct {
	*memcache.Client
	// contains filtered or unexported fields
}

MemcachedStore represents the cache with memcached persistence

func NewMemcachedStore

func NewMemcachedStore(hostList []string, defaultExpiration time.Duration) *MemcachedStore

NewMemcachedStore returns a MemcachedStore

func (*MemcachedStore) Add

func (c *MemcachedStore) Add(key string, value interface{}, expires time.Duration) error

Add (see CacheStore interface)

func (*MemcachedStore) Decrement

func (c *MemcachedStore) Decrement(key string, delta uint64) (uint64, error)

Decrement (see CacheStore interface)

func (*MemcachedStore) Delete

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

Delete (see CacheStore interface)

func (*MemcachedStore) Flush

func (c *MemcachedStore) Flush() error

Flush (see CacheStore interface)

func (*MemcachedStore) Get

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

Get (see CacheStore interface)

func (*MemcachedStore) Increment

func (c *MemcachedStore) Increment(key string, delta uint64) (uint64, error)

Increment (see CacheStore interface)

func (*MemcachedStore) Replace

func (c *MemcachedStore) Replace(key string, value interface{}, expires time.Duration) error

Replace (see CacheStore interface)

func (*MemcachedStore) Set

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

Set (see CacheStore interface)

type Option

type Option func(Options)

Option - how Options are passed as arguments

func WithSelectDatabase

func WithSelectDatabase(d int) Option

WithSync optional synchronous execution

type Options

type Options map[string]interface{}

Options = how options are represented

func GetOpts

func GetOpts(opt ...Option) Options

GetOpts - iterate the inbound Options and return a struct

type RedisStore

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

RedisStore represents the cache with redis persistence

func NewRedisCache

func NewRedisCache(host string, password string, defaultExpiration time.Duration, opt ...Option) *RedisStore

NewRedisCache returns a RedisStore until redigo supports sharding/clustering, only one host will be in hostList

func NewRedisCacheWithPool

func NewRedisCacheWithPool(pool *redis.Pool, defaultExpiration time.Duration) *RedisStore

NewRedisCacheWithPool returns a RedisStore using the provided pool until redigo supports sharding/clustering, only one host will be in hostList

func (*RedisStore) Add

func (c *RedisStore) Add(key string, value interface{}, expires time.Duration) error

Add (see CacheStore interface)

func (*RedisStore) Decrement

func (c *RedisStore) Decrement(key string, delta uint64) (newValue uint64, err error)

Decrement (see CacheStore interface)

func (*RedisStore) Delete

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

Delete (see CacheStore interface)

func (*RedisStore) ExpireAt

func (c *RedisStore) ExpireAt(key string, epoc uint64) error

ExpireAt - special case for Redis storage to handle updating the TTL for the entry for when a consumer wants to use this storage for something outside the standard cache contract.

func (*RedisStore) Flush

func (c *RedisStore) Flush() error

Flush (see CacheStore interface)

func (*RedisStore) Get

func (c *RedisStore) Get(key string, ptrValue interface{}) error

Get (see CacheStore interface)

func (*RedisStore) GetExpiresIn

func (c *RedisStore) GetExpiresIn(key string) (int64, error)

GetExpiresIn returns the number of milliseconds until the key expires returns ErrCacheNoTTL if no expiration is set on the entry

func (*RedisStore) Increment

func (c *RedisStore) Increment(key string, delta uint64) (uint64, error)

Increment (see CacheStore interface)

func (*RedisStore) IncrementAtomic

func (c *RedisStore) IncrementAtomic(key string, delta uint64) (uint64, error)

IncrementAtomic - special case for Redis storage to handle the need for atomic increments without a data race problem when a consumer wants to use this storage for something outside the standard cache contract.

func (*RedisStore) IncrementCheckSet

func (c *RedisStore) IncrementCheckSet(key string, delta uint64) (uint64, error)

IncrementCheckSet - special case where you want to increment a value ONLY if it doesn't change between your GET and SET

func (*RedisStore) MSetNX

func (c *RedisStore) MSetNX(expires time.Duration, kv ...interface{}) error

MSET add multiple items to redis cache if none of them already exists for the given keys. Return error otherwise. kv is a list of key value pairs: k1, v1, k2, v2, ...

func (*RedisStore) Mget

func (c *RedisStore) Mget(ptrValue []interface{}, keys ...string) error

MGet retrieves a list of items for the list of keys provided. If an item does not exist, an ErrCacheMiss is returned.

func (*RedisStore) Replace

func (c *RedisStore) Replace(key string, value interface{}, expires time.Duration) error

Replace (see CacheStore interface)

func (*RedisStore) Set

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

Set (see CacheStore interface)

Jump to

Keyboard shortcuts

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