Documentation ¶
Overview ¶
Package cache implements a wrapper on top of hashicorp/golang-lru with guava-style loader func. In addition for Get (i.e. load from cache if found and put to cache if absent) it adds a Key struct with record ID, site ID and invalidation scopes. Scopes used to evict matching records. Additional limits added for total cache size, mac number of keys and max size of the value. If exceeded it won't put to cache but will call loader func. Usually the cache involved on []byte response level, i.e. post-marshaling right before response's send.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FlusherRequest ¶
type FlusherRequest struct {
// contains filtered or unexported fields
}
FlusherRequest used as input for cache.Flush
func Flusher ¶
func Flusher(siteID string) FlusherRequest
Flusher makes new FlusherRequest with empty scopes
func (FlusherRequest) Scopes ¶
func (f FlusherRequest) Scopes(scopes ...string) FlusherRequest
Scopes adds scopes to FlusherRequest
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key for cache
func ParseKey ¶
ParseKey gets compound key created by Key func and split it to the actual key and scopes
type LoadingCache ¶
type LoadingCache interface { Get(key Key, fn func() ([]byte, error)) (data []byte, err error) // load from cache if found or put to cache and return Flush(req FlusherRequest) // evict matched records }
LoadingCache defines interface for caching
func NewMemoryCache ¶
func NewMemoryCache(options ...Option) (LoadingCache, error)
NewMemoryCache makes memoryCache implementation
type Option ¶
type Option func(lc cacheWithOpts) error
Option func type
func MaxCacheSize ¶
MaxCacheSize functional option defines the total size of cached data. By default it is 0, which means unlimited.
func MaxKeys ¶
MaxKeys functional option defines how many keys to keep. By default it is 0, which means unlimited.
func MaxValSize ¶
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.