thinkgo: github.com/thinkoner/thinkgo/cache Index | Files

package cache

import "github.com/thinkoner/thinkgo/cache"

Index

Package Files

cache.go memory_store.go redis_store.go repository.go store.go

func Register Uses

func Register(name string, adapter Store) error

Register Register a cache adapter available by the adapter name.

type MemoryStore Uses

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

func NewMemoryStore Uses

func NewMemoryStore(prefix string) *MemoryStore

NewStore Create a memory cache store

func (*MemoryStore) DeleteExpired Uses

func (s *MemoryStore) DeleteExpired()

Delete all expired items from the cache.

func (*MemoryStore) Exist Uses

func (s *MemoryStore) Exist(key string) bool

Exist check cache's existence in memory.

func (*MemoryStore) Flush Uses

func (s *MemoryStore) Flush() error

Remove all items from the cache.

func (*MemoryStore) Forget Uses

func (s *MemoryStore) Forget(key string) error

Forget Remove an item from the cache.

func (*MemoryStore) Get Uses

func (s *MemoryStore) Get(key string, val interface{}) error

Get get cached value by key. func (s *Store) Get(key string) (interface{}, error) {

func (*MemoryStore) GetPrefix Uses

func (s *MemoryStore) GetPrefix() string

GetPrefix Get the cache key prefix.

func (*MemoryStore) Put Uses

func (s *MemoryStore) Put(key string, val interface{}, timeout time.Duration) error

Put set cached value with key and expire time.

func (*MemoryStore) SetPrefix Uses

func (s *MemoryStore) SetPrefix(prefix string) *MemoryStore

SetPrefix Set the cache key prefix.

type RedisStore Uses

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

func NewRedisStore Uses

func NewRedisStore(pool *redis.Pool, prefix string) *RedisStore

NewStore Create a redis cache store

func (*RedisStore) Exist Uses

func (s *RedisStore) Exist(key string) bool

Exist check cache's existence in redis.

func (*RedisStore) Flush Uses

func (s *RedisStore) Flush() error

Remove all items from the cache.

func (*RedisStore) Forget Uses

func (s *RedisStore) Forget(key string) error

Forget Remove an item from the cache.

func (*RedisStore) Get Uses

func (s *RedisStore) Get(key string, val interface{}) error

Get get cached value by key.

func (*RedisStore) GetPrefix Uses

func (s *RedisStore) GetPrefix() string

GetPrefix Get the cache key prefix.

func (*RedisStore) Put Uses

func (s *RedisStore) Put(key string, val interface{}, timeout time.Duration) error

Put set cached value with key and expire time.

func (*RedisStore) SetPool Uses

func (s *RedisStore) SetPool(pool *redis.Pool) *RedisStore

SetPool Get the redis pool.

func (*RedisStore) SetPrefix Uses

func (s *RedisStore) SetPrefix(prefix string) *RedisStore

SetPrefix Set the cache key prefix.

type Repository Uses

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

func Cache Uses

func Cache(adapter interface{}) (*Repository, error)

NewCache Create a new cache by adapter name.

func NewRepository Uses

func NewRepository(store Store) *Repository

func (*Repository) Add Uses

func (r *Repository) Add(key string, val interface{}, timeout time.Duration) error

Add Store an item in the cache if the key does not exist.

func (*Repository) Clear Uses

func (r *Repository) Clear() error

Clear Remove all items from the cache.

func (*Repository) Delete Uses

func (r *Repository) Delete(key string) error

Delete Alias for the "Delete" method.

func (*Repository) Forget Uses

func (r *Repository) Forget(key string) error

Forget Remove an item from the cache.

func (*Repository) Get Uses

func (r *Repository) Get(key string, val interface{}) error

Get Retrieve an item from the cache by key.

func (*Repository) GetStore Uses

func (r *Repository) GetStore() Store

GetStore Get the cache store implementation.

func (*Repository) Has Uses

func (r *Repository) Has(key string) bool

Has Determine if an item exists in the cache.

func (*Repository) Pull Uses

func (r *Repository) Pull(key string, val interface{}) error

Pull Retrieve an item from the cache and delete it.

func (*Repository) Put Uses

func (r *Repository) Put(key string, val interface{}, timeout time.Duration) error

Put Store an item in the cache.

func (*Repository) Remember Uses

func (r *Repository) Remember(key string, val interface{}, timeout time.Duration, callback func() interface{}) error

Remember Get an item from the cache, or store the default value.

func (*Repository) Set Uses

func (r *Repository) Set(key string, val interface{}, timeout time.Duration) error

Set Store an item in the cache.

type Store Uses

type Store interface {
    // Get get cached value by key.
    Get(key string, val interface{}) error

    // Put set cached value with key and expire time.
    Put(key string, val interface{}, timeout time.Duration) error

    // Exist check cache's existence in redis.
    Exist(key string) bool

    // Forget Remove an item from the cache.
    Forget(key string) error

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

Package cache imports 7 packages (graph). Updated 2019-08-21. Refresh now. Tools for package owners.