caches

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 6 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RegexCache = NewLoadingCache()

RegexCache is the default loading cache used for caching the compiled regex expression. If the default size is too big/small and/or a cache limit isn't desired at all, caller can simply replace the cache during global initialization. But be aware it's global so any packages uses this package inside your process will be affected.

View Source
var TimeLocationCache = NewLoadingCache()

TimeLocationCache is the default loading cache used for caching *time.Location object If the default size is too big/small and/or a cache limit isn't desired at all, caller can simply replace the cache during global initialization. But be aware it's global so any packages uses this package inside your process will be affected.

View Source
var XPathExprCache = NewLoadingCache()

XPathExprCache is the default loading cache used for caching the compiled xpath expression. If the default size is too big/small and/or a cache limit isn't desired at all, caller can simply replace the cache during global initialization. But be aware it's global so any packages uses this package inside your process will be affected.

Functions

func GetRegex

func GetRegex(pattern string) (*regexp.Regexp, error)

GetRegex compiles a given regex pattern and returns a compiled *regexp.Regexp or error.

func GetTimeLocation added in v0.0.4

func GetTimeLocation(tz string) (*time.Location, error)

GetTimeLocation loads a time.Location object based on IANA time zone string.

func GetXPathExpr

func GetXPathExpr(expr string) (*xpath.Expr, error)

GetXPathExpr compiles a given xpath expression string and returns a compiled *xpath.Expr or error.

Types

type LoadFunc

type LoadFunc func(key interface{}) (interface{}, error)

LoadFunc is the type of the loading function.

type LoadingCache

type LoadingCache struct {
	// contains filtered or unexported fields
}

LoadingCache is a key/value cache with a user specified loading function and an optional capacity. If a key isn't present in the cache, load function will be called to create a value for the key and the value will be stored into the cache as well as returned to the caller. If no capacity is specified, then a reasonable default cache capacity is used (to prevent accidental and unintentional unlimited cache growth). If 0 capacity is specified, then cache capacity is removed - be careful of unlimited cache growth. If >0 capacity is specified and reached, cache entry eviction takes place in LRU fashion. The cache is thread-safe.

func NewLoadingCache

func NewLoadingCache(capacity ...int) *LoadingCache

NewLoadingCache creates a new LoadingCache.

func (*LoadingCache) DumpForTest

func (c *LoadingCache) DumpForTest() map[interface{}]interface{}

DumpForTest returns all the entries in the cache. Not thread-safe and should really only be used in tests as the function name suggests.

func (*LoadingCache) Get

func (c *LoadingCache) Get(key interface{}, load LoadFunc) (interface{}, error)

Get tries to fetch the value for a key from the cache; if not found, it will call the load function to create the value for the key, store it into the cache and return the value.

Jump to

Keyboard shortcuts

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