...

Package lru

import "k8s.io/utils/lru"
Overview
Index

Overview ▾

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.

type Cache

Cache is a thread-safe fixed size LRU cache.

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

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.

type EvictionFunc

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

type Key

type Key = groupcache.Key