cache

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package cache contains cache implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRU

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

LRU implements a fixed-size LRU cache with string keys. It can be used concurrently from multiple goroutines.

func NewLRU

func NewLRU(max int) *LRU

NewLRU returns a new LRU that will hold up to max items.

func (*LRU) Get

func (lru *LRU) Get(key string) (val interface{}, ok bool)

Get returns the value associated with key. If the key isn't present in the map, nil and false are returned.

func (*LRU) Set

func (lru *LRU) Set(key string, val interface{})

Set saves a mapping from key to val.

func (*LRU) TestAndSet

func (lru *LRU) TestAndSet(key string, val interface{}, test func(interface{}) bool) bool

TestAndSet saves a mapping from key to val and returns true if key isn't already present or if test returns true when passed the existing value. If test returns false, the mapping is not saved and false is returned. The new mapping is set unconditionally (and true is returned) if test is nil.

Jump to

Keyboard shortcuts

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