namedmemcache

package
v0.82.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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.

Jump to

Keyboard shortcuts

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