xcache_redis

package
v0.2.55 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = errors.New("cache: key is missing")

Functions

This section is empty.

Types

type Codec

type Codec struct {
	Redis xservice.IRedis

	Marshal   func(interface{}) ([]byte, error)
	Unmarshal func([]byte, interface{}) error
	// contains filtered or unexported fields
}

func (*Codec) Delete

func (cd *Codec) Delete(key string) error

func (*Codec) DeleteContext

func (cd *Codec) DeleteContext(ctx context.Context, key string) error

func (*Codec) Exists

func (cd *Codec) Exists(key string) bool

Exists reports whether object for the given key exists.

func (*Codec) ExistsContext

func (cd *Codec) ExistsContext(ctx context.Context, key string) bool

func (*Codec) Get

func (cd *Codec) Get(key string, object interface{}) error

Get gets the object for the given key.

func (*Codec) GetContext

func (cd *Codec) GetContext(ctx context.Context, key string, object interface{}) error

func (*Codec) Once

func (cd *Codec) Once(item *Item) error

Once gets the item.Object for the given item.Key from the cache or executes, caches, and returns the results of the given item.Func, making sure that only one execution is in-flight for a given item.Key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.

func (*Codec) Set

func (cd *Codec) Set(item *Item) error

Set caches the item.

func (*Codec) Stats

func (cd *Codec) Stats() *Stats

Stats returns cache statistics.

func (*Codec) UseLocalCache

func (cd *Codec) UseLocalCache(maxLen int, expiration time.Duration)

UseLocalCache causes Codec to cache items in local LRU cache.

type Item

type Item struct {
	Ctx context.Context

	Key    string
	Object interface{}

	// Func returns object to be cached.
	Func func() (interface{}, error)

	// Expiration is the cache expiration time.
	// Default expiration is 1 hour.
	Expiration time.Duration
}

func (*Item) Context

func (item *Item) Context() context.Context

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) *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) 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) Increment

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

Increment (see CacheStore interface)

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)

type Stats

type Stats struct {
	Hits        uint64
	Misses      uint64
	LocalHits   uint64
	LocalMisses uint64
}

Jump to

Keyboard shortcuts

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