Documentation
¶
Index ¶
- Variables
- func CacheEvict(cache cache.CacheServer, name string, options ...CacheEvictOptions) endpoint.Middleware
- func CachePut(cache cache.CacheServer, name string, options ...CachePutOptions) endpoint.Middleware
- func Cacheable(cache cache.CacheServer, name string, options ...CacheableOptions) endpoint.Middleware
- func Database(dbfactory db.ConnectionFactory, key constants.DatabaseContextValue) endpoint.Middleware
- func DatabaseWithTx(dbfactory db.ConnectionFactory, key constants.DatabaseContextValue) endpoint.Middleware
- type CacheEvictOptions
- type CachePutOptions
- type CacheableOptions
- type EntryCache
Constants ¶
This section is empty.
Variables ¶
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
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
func Database ¶
func Database(dbfactory db.ConnectionFactory, key constants.DatabaseContextValue) endpoint.Middleware
func DatabaseWithTx ¶
func DatabaseWithTx(dbfactory db.ConnectionFactory, key constants.DatabaseContextValue) endpoint.Middleware
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