utilsk8s.io/utils/lru Index | Files

package lru

import "k8s.io/utils/lru"

Copyright 2021 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Types

type Cache

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

Cache is a thread-safe fixed size LRU cache.

func New

func New(size int) *Cache

New creates an LRU of the given size.

func NewWithEvictionFunc

func NewWithEvictionFunc(size int, f EvictionFunc) *Cache

NewWithEvictionFunc creates an LRU of the given size with the given eviction func.

func (*Cache) Add

func (c *Cache) Add(key Key, value interface{})

Add adds a value to the cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear purges all stored items from the cache.

func (*Cache) Get

func (c *Cache) Get(key Key) (value interface{}, ok bool)

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

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Remove

func (c *Cache) Remove(key Key)

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

func (*Cache) SetEvictionFunc

func (c *Cache) SetEvictionFunc(f EvictionFunc) error

SetEvictionFunc updates the eviction func

type EvictionFunc

type EvictionFunc = func(key Key, value interface{})

type Key

type Key = groupcache.Key

Source Files

lru.go

Version
v0.0.0-20250321185631-1f6e0b77f77e (latest)
Published
Mar 21, 2025
Platform
js/wasm
Imports
3 packages
Last checked
1 month ago

Tools for package owners.