Movatterモバイル変換


[0]ホーム

URL:


lru

package
v1.92.2Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:3Imported by:1

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package lru contains a typed Least-Recently-Used cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

typeCache

type Cache[Kcomparable, Vany] struct {// MaxEntries is the maximum number of cache entries before// an item is evicted. Zero means no limit.MaxEntriesint// contains filtered or unexported fields}

Cache is container type keyed by K, storing V, optionally evicting the leastrecently used items if a maximum size is exceeded.

The zero value is valid to use.

It is not safe for concurrent access.

The current implementation is just the traditional LRU linked list; a futureimplementation may be more advanced to avoid pathological cases.

func (*Cache[K, V])Clearadded inv1.68.0

func (c *Cache[K, V]) Clear()

Clear removes all items from the cache.

func (*Cache[K, V])Contains

func (c *Cache[K, V]) Contains(key K)bool

Contains reports whether c contains key.

If found, key is moved to the front of the LRU.

func (*Cache[K, V])Delete

func (c *Cache[K, V]) Delete(key K)

Delete removes the provided key from the cache if it was present.

func (*Cache[K, V])DeleteOldest

func (c *Cache[K, V]) DeleteOldest()

DeleteOldest removes the item from the cache that was leastrecently accessed. It is a no-op if the cache is empty.

func (*Cache[K, V])DumpHTMLadded inv1.50.0

func (c *Cache[K, V]) DumpHTML(wio.Writer)

DumpHTML writes the state of the cache to the given writer,formatted as an HTML table.

func (*Cache[K, V])ForEachadded inv1.50.0

func (c *Cache[K, V]) ForEach(fn func(K, V))

ForEach calls fn for each entry in the cache, from most recentlyused to least recently used.

func (*Cache[K, V])Get

func (c *Cache[K, V]) Get(key K) V

Get looks up a key's value from the cache, returning eitherthe value or the zero value if it not present.

If found, key is moved to the front of the LRU.

func (*Cache[K, V])GetOk

func (c *Cache[K, V]) GetOk(key K) (value V, okbool)

GetOk looks up a key's value from the cache, also reporting whetherit was present.

If found, key is moved to the front of the LRU.

func (*Cache[K, V])Len

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

Len returns the number of items in the cache.

func (*Cache[K, V])PeekOkadded inv1.50.0

func (c *Cache[K, V]) PeekOk(key K) (value V, okbool)

PeekOk looks up the key's value from the cache, also reportingwhether it was present.

Unlike GetOk, PeekOk does not move key to the front of theLRU. This should mostly be used for non-intrusive debug inspectionof the cache.

func (*Cache[K, V])Set

func (c *Cache[K, V]) Set(key K, value V)

Set adds or replaces a value to the cache, set or updating its associatedvalue.

If MaxEntries is non-zero and the length of the cache is greaterafter any addition, the least recently used value is evicted.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp