middleware

package
v1.16.3 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyGenerator = func(name string, args interface{}) string {
	algorithm := md5.New()
	algorithm.Write([]byte(fmt.Sprintf("%v%v", name, args)))
	return fmt.Sprintf("%v:%v", name, hex.EncodeToString(algorithm.Sum(nil)))
}

DefaultKeyGenerator generator

View Source
var DefaultListener = func(event string, nameOrKey string) {}

DefaultListener listener

Functions

func CacheEvict added in v1.13.0

func CacheEvict(cache cache.CacheServer, name string, options ...CacheEvictOptions) endpoint.Middleware

CacheEvict Now, what would be the problem with making all methods Cacheable? The problem is size – we don't want to populate the cache with values that we don't need often. Caches can grow quite large, quite fast, and we could be holding on to a lot of stale or unused data. The CacheEvict is used to indicate the removal of one or more/all values – so that fresh values can be loaded into the cache again.

func CachePut added in v1.13.0

func CachePut(cache cache.CacheServer, name string, options ...CachePutOptions) endpoint.Middleware

CachePut While CacheEvict reduces the overhead of looking up entries in a large cache by removing stale and unused entries, ideally, you want to avoid evicting too much data out of the cache. Instead, you'd want to selectively and intelligently update the entries whenever they're altered. With the CachePut annotation, you can update the content of the cache without interfering the method execution. That is, the method would always be executed and the result cached.

func Cacheable

func Cacheable(cache cache.CacheServer, name string, options ...CacheableOptions) endpoint.Middleware

Cacheable The simplest way to enable caching behavior for a method is to demarcate it with Cacheable and parameterize it with the name of the cache where the results would be stored

Types

type CacheEvictOptions added in v1.13.0

type CacheEvictOptions struct {
	TTL          time.Duration
	AllEntries   bool
	OnListener   func(event string, key string)
	KeyGenerator func(name string, args interface{}) string
}

CacheEvictOptions cache configurations

type CachePutOptions added in v1.13.0

type CachePutOptions struct {
	TTL          time.Duration
	OnListener   func(event string, key string)
	KeyGenerator func(name string, args interface{}) string
}

CachePutOptions cache configurations

type CacheableOptions added in v1.13.0

type CacheableOptions struct {
	TTL          time.Duration
	OnListener   func(event string, key string)
	KeyGenerator func(name string, args interface{}) string
}

CacheableOptions cache configurations

type EntryCache added in v1.12.1

type EntryCache struct {
	Status int         `json:"status"`
	Value  interface{} `json:"value"`
}

EntryCache cache container

Jump to

Keyboard shortcuts

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