...

Package cache

import "github.com/gin-gonic/contrib/cache"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Constants
Variables
func Cache(store *CacheStore) gin.HandlerFunc
func CachePage(store CacheStore, expire time.Duration, handle gin.HandlerFunc) gin.HandlerFunc
func SiteCache(store CacheStore, expire time.Duration) gin.HandlerFunc
type CacheStore
type InMemoryStore
    func NewInMemoryStore(defaultExpiration time.Duration) *InMemoryStore
    func (c *InMemoryStore) Add(key string, value interface{}, expires time.Duration) error
    func (c *InMemoryStore) Decrement(key string, n uint64) (uint64, error)
    func (c *InMemoryStore) Delete(key string) error
    func (c *InMemoryStore) Flush() error
    func (c *InMemoryStore) Get(key string, value interface{}) error
    func (c *InMemoryStore) Increment(key string, n uint64) (uint64, error)
    func (c *InMemoryStore) Replace(key string, value interface{}, expires time.Duration) error
    func (c *InMemoryStore) Set(key string, value interface{}, expires time.Duration) error
type MemcachedStore
    func NewMemcachedStore(hostList []string, defaultExpiration time.Duration) *MemcachedStore
    func (c *MemcachedStore) Add(key string, value interface{}, expires time.Duration) error
    func (c *MemcachedStore) Decrement(key string, delta uint64) (uint64, error)
    func (c *MemcachedStore) Delete(key string) error
    func (c *MemcachedStore) Flush() error
    func (c *MemcachedStore) Get(key string, value interface{}) error
    func (c *MemcachedStore) Increment(key string, delta uint64) (uint64, error)
    func (c *MemcachedStore) Replace(key string, value interface{}, expires time.Duration) error
    func (c *MemcachedStore) Set(key string, value interface{}, expires time.Duration) error
type RedisStore
    func NewRedisCache(host string, password string, defaultExpiration time.Duration) *RedisStore
    func (c *RedisStore) Add(key string, value interface{}, expires time.Duration) error
    func (c *RedisStore) Decrement(key string, delta uint64) (newValue uint64, err error)
    func (c *RedisStore) Delete(key string) error
    func (c *RedisStore) Flush() error
    func (c *RedisStore) Get(key string, ptrValue interface{}) error
    func (c *RedisStore) Increment(key string, delta uint64) (uint64, error)
    func (c *RedisStore) Replace(key string, value interface{}, expires time.Duration) error
    func (c *RedisStore) Set(key string, value interface{}, expires time.Duration) error

Package files

cache.go inmemory.go memcached.go redis.go serializer.go

Constants

const (
    DEFAULT              = time.Duration(0)
    FOREVER              = time.Duration(-1)
    CACHE_MIDDLEWARE_KEY = "gincontrib.cache"
)

Variables

var (
    PageCachePrefix = "gincontrib.page.cache"
    ErrCacheMiss    = errors.New("cache: key not found.")
    ErrNotStored    = errors.New("cache: not stored.")
    ErrNotSupport   = errors.New("cache: not support.")
)

func Cache

func Cache(store *CacheStore) gin.HandlerFunc

Cache Middleware

func CachePage

func CachePage(store CacheStore, expire time.Duration, handle gin.HandlerFunc) gin.HandlerFunc

Cache Decorator

func SiteCache

func SiteCache(store CacheStore, expire time.Duration) gin.HandlerFunc

type CacheStore

type CacheStore interface {
    Get(key string, value interface{}) error
    Set(key string, value interface{}, expire time.Duration) error
    Add(key string, value interface{}, expire time.Duration) error
    Replace(key string, data interface{}, expire time.Duration) error
    Delete(key string) error
    Increment(key string, data uint64) (uint64, error)
    Decrement(key string, data uint64) (uint64, error)
    Flush() error
}

type InMemoryStore

type InMemoryStore struct {
    cache.Cache
}

func NewInMemoryStore

func NewInMemoryStore(defaultExpiration time.Duration) *InMemoryStore

func (*InMemoryStore) Add

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

func (*InMemoryStore) Decrement

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

func (*InMemoryStore) Delete

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

func (*InMemoryStore) Flush

func (c *InMemoryStore) Flush() error

func (*InMemoryStore) Get

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

func (*InMemoryStore) Increment

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

func (*InMemoryStore) Replace

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

func (*InMemoryStore) Set

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

type MemcachedStore

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

func NewMemcachedStore

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

func (*MemcachedStore) Add

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

func (*MemcachedStore) Decrement

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

func (*MemcachedStore) Delete

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

func (*MemcachedStore) Flush

func (c *MemcachedStore) Flush() error

func (*MemcachedStore) Get

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

func (*MemcachedStore) Increment

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

func (*MemcachedStore) Replace

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

func (*MemcachedStore) Set

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

type RedisStore

Wraps the Redis client to meet the Cache interface.

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

func NewRedisCache

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

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

func (*RedisStore) Decrement

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

func (*RedisStore) Delete

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

func (*RedisStore) Flush

func (c *RedisStore) Flush() error

func (*RedisStore) Get

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

func (*RedisStore) Increment

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

func (*RedisStore) Replace

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

func (*RedisStore) Set

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

Subdirectories

Name Synopsis
..
example