namedmemcache

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2020 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 invoced only once for this cache.

Jump to

Keyboard shortcuts

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