nonblocking

package
v4.0.0-...-b8b0360 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE_list file.

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictCallback

type EvictCallback[K comparable, V any] func(key K, value V)

EvictCallback is used to get a callback when a cache entry is evicted

type LRU

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

LRU implements a non-thread safe fixed size LRU cache

func NewLRU

func NewLRU[K comparable, V any](size int, onEvict EvictCallback[K, V]) (*LRU[K, V], error)

NewLRU constructs an LRU of the given size

func (*LRU[K, V]) Add

func (c *LRU[K, V]) Add(key K, value V) (evicted bool)

Add adds a value to the cache. Returns true if an eviction occurred.

func (*LRU[K, V]) Get

func (c *LRU[K, V]) Get(key K) (value V, ok bool)

Get looks up a key's value from the cache.

func (*LRU[K, V]) Len

func (c *LRU[K, V]) Len() int

Len returns the number of items in the cache.

func (*LRU[K, V]) Resize

func (c *LRU[K, V]) Resize(size int) (evicted int)

Resize changes the cache size.

Jump to

Keyboard shortcuts

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