cache

package
v0.14.1-bitcore Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(duration string, storage Storage, handler func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request)

Middleware is the cache interface for http requests

Types

type Item

type Item struct {
	Content    []byte
	Expiration int64
}

Item is a cached reference

func (Item) Expired

func (item Item) Expired() bool

Expired returns true if the item has expired.

type MemoryCache

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

MemoryCache mecanism for caching strings in memory

func NewMemoryCache

func NewMemoryCache() *MemoryCache

NewMemoryCache creates a new in memory storage

func (MemoryCache) Get

func (c MemoryCache) Get(key string) []byte

Get a cached content by key

func (MemoryCache) Set

func (c MemoryCache) Set(key string, content []byte, duration time.Duration)

Set a cached content by key

type RedisCache

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

RedisCache storage mecanism for caching strings in memory

func NewRedisCache

func NewRedisCache(url string) (*RedisCache, error)

NewRedisCache creates a new redis storage

func (RedisCache) Get

func (c RedisCache) Get(key string) []byte

Get a cached content by key

func (RedisCache) Set

func (c RedisCache) Set(key string, content []byte, duration time.Duration)

Set a cached content by key

type Storage

type Storage interface {
	Get(key string) []byte
	Set(key string, content []byte, duration time.Duration)
}

Storage mecanism for caching strings

Jump to

Keyboard shortcuts

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