sizecache

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpireCallback

type ExpireCallback func(key interface{})

type SizeCache

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

func New

func New(maxSize uint64) *SizeCache

New creates a SizeCache that will hold up to |maxSize| item data.

func NewWithExpireCallback

func NewWithExpireCallback(maxSize uint64, cb ExpireCallback) *SizeCache

NewWithExpireCallback creates a SizeCache that will hold up to |maxSize| item data, and will call cb(key) when the item corresponding with that key expires.

func (*SizeCache) Add

func (c *SizeCache) Add(key interface{}, size uint64, value interface{})

Add will add this element to the cache at the back of the queue as long it's size does not exceed maxSize. If the addition of this entry causes the size of the cache to exceed maxSize, the necessary entries at the front of the queue will be deleted in order to keep the total cache size below maxSize.

func (*SizeCache) Drop

func (c *SizeCache) Drop(key interface{})

Drop will remove the element associated with the given key from the cache.

func (*SizeCache) Get

func (c *SizeCache) Get(key interface{}) (interface{}, bool)

Get checks the searches the cache for an entry. If it exists, it moves it's lru entry to the back of the queue and returns (value, true). Otherwise, it returns (nil, false).

func (*SizeCache) Size

func (c *SizeCache) Size() uint64

Jump to

Keyboard shortcuts

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