...

Package cache

import "golang.conradwood.net/go-easyops/cache"
Overview
Index

Overview ▾

package cache provides a basic, safe in-memory cache. This is currently per-instance. a patch to make it per-cluster is welcome. (perhaps using redis?)

type Cache

type Cache struct {
    MaxLifetime time.Duration
    // contains filtered or unexported fields
}

func Clear

func Clear(cacheName string) ([]*Cache, error)

clear the entire cache with this name and return cache objects (which cleared)

func New

func New(name string, lifetime time.Duration, maxSizeInMB int) *Cache

create a new cache. "name" must be a prometheus metric compatible name and unique throughout good practice: prefix it with servicepackagename. for example:

servicename: "lbproxy.LBProxyService"

-> cachename: "lbproxy_tokencache"

func (*Cache) Clear

func (c *Cache) Clear()

clear this cache (that is: remove all entries in it)

func (*Cache) Evict

func (c *Cache) Evict(key string)

evict (aka remove) a specific key from this cache

func (*Cache) Get

func (c *Cache) Get(key string) interface{}

get something from the cache (specified by key)

func (*Cache) Keys

func (c *Cache) Keys() []string

get all the keys from the cache

func (*Cache) Name

func (c *Cache) Name() string

return the name of this cache

func (*Cache) Put

func (c *Cache) Put(key string, value interface{})

put something into this cache

func (*Cache) PutWithExpiry

func (c *Cache) PutWithExpiry(key string, value interface{}, expiry *time.Time)

put something into this cache, with a specific expiry time

type CachingResolver

type CachingResolver interface {
    Retrieve(key string, fr func(string) (interface{}, error)) (interface{}, error)
    RetrieveContext(ctx context.Context, key string, fr func(context.Context, string) (interface{}, error)) (interface{}, error)
    SetRefreshAfter(time.Duration)
    SetAsyncRetriever(fr func(string) (interface{}, error))
    Evict(key string)
    Clear()
    Keys() []string
}

func NewResolvingCache

func NewResolvingCache(name string, lifetime time.Duration, maxLimitEntries int) CachingResolver