cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(key string, scopes ...string) string

Key makes full key from primary key and scopes

func ParseKey

func ParseKey(fullKey string) (key string, scopes []string, err error)

ParseKey gets compound key created by Key func and split it to the actual key and scopes

func URLKey

func URLKey(r *http.Request) string

URLKey gets url from request to use it as cache key admins will have different keys in order to prevent leak of admin-only data to regular users

Types

type LoadingCache

type LoadingCache interface {
	Get(key string, fn func() ([]byte, error)) (data []byte, err error)
	Flush(scopes ...string)
}

LoadingCache defines interface for caching

func NewMemoryCache

func NewMemoryCache(options ...Option) (LoadingCache, error)

NewMemoryCache makes memoryCache implementation

type Option

type Option func(lc *memoryCache) error

Option func type

func MaxCacheSize

func MaxCacheSize(max int64) Option

MaxCacheSize functional option defines the total size of cached data. By default it is 0, which means unlimited.

func MaxKeys

func MaxKeys(max int) Option

MaxKeys functional option defines how many keys to keep. By default it is 0, which means unlimited.

func MaxValSize

func MaxValSize(max int) Option

MaxValSize functional option defines the largest value's size allowed to be cached By default it is 0, which means unlimited.

func PostFlushFn

func PostFlushFn(postFlushFn func()) Option

PostFlushFn functional option defines how callback function called after each Flush.

Jump to

Keyboard shortcuts

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