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() (any, error)) (any, 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.121.2
Published
Jan 5, 2024
Platform
linux/amd64
Imports
2 packages
Last checked
43 minutes ago

Tools for package owners.