package namedmemcache

import "github.com/gohugoio/hugo/cache/namedmemcache"

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.

Index

Types

type Cache

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

Cache holds the cached values.

func New

func New() *Cache

New creates a new cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear clears the cache state.

func (*Cache) GetOrCreate

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 invoked only once for this cache.

Source Files

named_cache.go

Version
v0.90.1
Published
Dec 10, 2021
Platform
js/wasm
Imports
2 packages
Last checked
1 hour ago

Tools for package owners.