Help us shape the future of Go! Take the 2026 Go Developer Survey

genericache

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 1 Imported by: 0

README

Generic cache implementation that uses go generics.

Mainly just an excuse to get familiar with go generics, but possibly useful.

Documentation

Overview

Package genericache is a simple cache with no evictions, no expiration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filler

type Filler[K comparable, V any] func(key K) (V, error)

Filler is a function that is meant to fetch values on cache miss. An error returned from this function will be returned from the GeneriCache.Get() method.

type GeneriCache

type GeneriCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

GeneriCache implements a simple cache with no eviction.

func NewGeneriCache

func NewGeneriCache[K comparable, V any](fillFunc Filler[K, V], retryErrors bool) *GeneriCache[K, V]

NewGeneriCache - factory method for GeneriCache. Use this to initialize. fillFunc is a filler method meant to fill the cache on cache miss. retryErrors indicates whether an error received from fillFunc should indicate to try the filler function on next Get() operation. If this is false, it will return the same error over and over and not call fillFunc more than once per key. If true, it will call fillFunc on subsequent Get() calls until error is nil.

func (*GeneriCache[K, V]) Get

func (gc *GeneriCache[K, V]) Get(key K) (V, error)

Get - Get a value from the cache. On cache miss, it will call the Filler function.

Jump to

Keyboard shortcuts

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