hugo: Index | Files

package namedmemcache

import ""

Package namedmemcache provides a memory cache with a named lock. This is suitable for situations where creating the cached resource can be time consuming or otherwise resource hungry, or in situations where a "once only per key" is a requirement.


Package Files


type Cache Uses

type Cache struct {
    // contains filtered or unexported fields

Cache holds the cached values.

func New Uses

func New() *Cache

New creates a new cache.

func (*Cache) Clear Uses

func (c *Cache) Clear()

Clear clears the cache state.

func (*Cache) GetOrCreate Uses

func (c *Cache) GetOrCreate(key string, create func() (interface{}, error)) (interface{}, error)

GetOrCreate tries to get the value with the given cache key, if not found create will be called and cached. This method is thread safe. It also guarantees that the create func for a given key is invoced only once for this cache.

Package namedmemcache imports 2 packages (graph) and is imported by 11 packages. Updated 2019-08-13. Refresh now. Tools for package owners.