cache

package module
v0.0.0-...-34b0d15 Latest Latest
Warning

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

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

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get retrieves an element based on a key, returning nil if the element
	// does not exist
	Get(key string) interface{}

	// Put adds an element to the cache, returning the previous element
	Put(key string, value interface{}) interface{}

	// Delete deletes an element in the cache
	Delete(key string)
}

A Cache is a generalized interface to a cache. See LRU for a specific implementation (bounded cache with LRU eviction)

func New

func New(maxSize int, opts *Options) Cache

New creates a new cache with the given options

func NewLRU

func NewLRU(maxSize int) Cache

NewLRU creates a new LRU cache of the given size, setting initial capacity to the max size

func NewLRUWithInitialCapacity

func NewLRUWithInitialCapacity(initialCapacity, maxSize int) Cache

NewLRUWithInitialCapacity creates a new LRU cache with an initial capacity and a max size

type Options

type Options struct {
	// TTL controls the time-to-live for a given cache entry.  Cache entries that
	// are older than the TTL will not be returned
	TTL time.Duration

	// InitialCapacity controls the initial capacity of the cache
	InitialCapacity int

	// RemovedFunc is an optional function called when an element
	// is scheduled for deletion
	RemovedFunc RemovedFunc
}

Options control the behavior of the cache

type RemovedFunc

type RemovedFunc func(interface{})

RemovedFunc is a type for notifying applications when an item is scheduled for removal from the Cache. If f is a function with the appropriate signature and i is the interface{} scheduled for deletion, Cache calls go f(i)

Jump to

Keyboard shortcuts

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