cache

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache provides unified access to cache backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Normalize

func Normalize(key, prefix string) string

Normalize returns valid cache key. It can automatically detect prefixed/non-prefixed cache key and format the key properly.

func NormalizeMulti

func NormalizeMulti(keys []string, prefix string) []string

NormalizeMulti is batch version of Normalize.

Types

type FetchInfo

type FetchInfo struct {
	RemoteURL  string
	StatusCode int
	Duration   time.Duration
}

FetchInfo is the container for the information data from a backend.

type Fetcher

type Fetcher interface {
	Fetch(key string, r *http.Request) ([]byte, *FetchInfo, error)
	FetchMulti(keys []string, r *http.Request) (map[string][]byte, map[string]*FetchInfo, error)
}

Fetcher is the interface for getting cache data from remote backend based on given key(s).

type Normalizer

type Normalizer interface {
	Normalize(key string) string
	NormalizeMulti(keys []string) []string
}

Normalizer is the interface for normalizing cache key

type Provider

type Provider interface {
	Storage
	Normalizer
	Namespace() string
}

Provider wraps Storage interface with additional functionalities.

func NewProvider

func NewProvider(z Storage, prefix string) Provider

NewProvider returns Provider from a Storage and prefix.

type Reader

type Reader interface {
	Name() string
	Read(key string) ([]byte, error)
	ReadMulti(keys []string) (map[string][]byte, error)
}

Reader is the interface for cache backend implementation for reading cache data.

type RemoteOption

type RemoteOption struct {
	Transport http.RoundTripper
	Timeout   time.Duration
	Resolver  Resolver
}

RemoteOption is the configuration option for the RemoteProvider.

type RemoteProvider

type RemoteProvider interface {
	Provider
	Resolver
	Fetcher
}

RemoteProvider enhances Provider with remote functionalities.

func NewRemoteProvider

func NewRemoteProvider(p Provider, opt RemoteOption) RemoteProvider

NewRemoteProvider returns RemoteProvider from a Provider and RemoteOption.

type Resolver

type Resolver interface {
	Resolve(key string, r *http.Request) (*http.Request, error)
}

Resolver is the interface for resolving cache key to http request.

type Storage

type Storage interface {
	Writer
	Reader
	Delete(key string) error
}

Storage is the interface for writing and reading data.

type Writer

type Writer interface {
	Write(key string, value []byte, expiration time.Duration) error
}

Writer is the interface for cache backend implementation for writing cache data.

Jump to

Keyboard shortcuts

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