Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMemCache ¶
func NewMemCache(opts ...CacheOptions) *cache
Types ¶
type CacheOption ¶
type CacheOptions ¶
type CacheOptions func(opt *CacheOption)
type Key ¶
type Key interface {
// Hash is used for internal mapping. It has to be unique and non-pointer
Hash() interface{}
}
type MemCache ¶
type MemCache interface { // GetOrLoad try to get cached entry, using provided validator to check the entry, if not valid, try to load it. // If there is any error during load, it's cached and returned from this method // Note: this method is the main method for this in-memory cache GetOrLoad(ctx context.Context, k Key, loader LoadFunc, validator ValidateFunc) (interface{}, error) // Update Utility method, force change the loaded entry's value. // If given key doesn't exist or is invalidated, this function does nothing and return false, otherwise returns true. // If there is any error during update, it's cached and returned from this method // If this Update is used while the entry is loading, it will wait until loading finishes and then perform update Update(ctx context.Context, k Key, updater UpdateFunc) (bool, error) // Delete Utility method, remove the cached entry of given key, regardless if it's valid Delete(k Key) // Reset Utility method, reset the cache and remove all entries, regardless if they are valid Reset() // Evict Utility method, cleanup the cache, removing any invalid entries, free up memory // Note: this process is also performed periodically, normally there is no need to call this function manually Evict() }
type UpdateFunc ¶
type ValidateFunc ¶
Click to show internal directories.
Click to hide internal directories.