cache

package
v0.0.0-...-794a47f Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultExpiration default expiration second
	DefaultExpiration = 5 * time.Second
	// StayForever no expiration
	StayForever = time.Duration(-1)
	// CacheMiddlewareKey key for cache middleware
	CacheMiddlewareKey = "echo-middleware.cache"
)

Variables

View Source
var (
	PageCachePrefix = "echo-middleware.page.cache"
	ErrCacheMiss    = errors.New("cache: key not found.")
	ErrNotStored    = errors.New("cache: not stored.")
	ErrNotSupport   = errors.New("cache: not support.")

	// DefaultCacheConfig is the default cache middleware config.
	DefaultCacheConfig = Config{
		Expire:  DefaultExpiration,
		Skipper: emw.DefaultSkipper,
	}
)

Functions

func JSONPostPageCache

func JSONPostPageCache(config Config, keys ...string) echo.MiddlewareFunc

JSONPostPageCache middleware for page cache with json keys

func SetCacheStore

func SetCacheStore(store Store) echo.MiddlewareFunc

SetCacheStore set cache store to context for next processes

Types

type Config

type Config struct {
	Expire time.Duration
	// Skipper defines a function to skip middleware.
	Skipper emw.Skipper
}

Config defines the config for cache middleware.

type InMemoryStore

type InMemoryStore struct {
	gocache.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 int64) (int64, 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 int64) (int64, 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 Store

type Store 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 int64) (int64, error)
	Decrement(key string, data int64) (int64, error)
	Flush() error
}

Store defines the interface for cache store

Jump to

Keyboard shortcuts

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