lruttl

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package lruttl implements an LRU cache with TTL

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func New

func New(maxEntries int, expiry time.Duration) *Cache

New creates a new Cache. If maxEntries is zero, the cache has no limit. if expiry is zero, records do not expire.

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, bringing it to the front.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Oldest

func (c *Cache) Oldest() (t time.Time, ok bool)

Oldest returns the time of the oldest item in the cache.

func (*Cache) Peek

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

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

func (*Cache) Remove

func (c *Cache) Remove(key Key)

Remove removes the provided key from the cache.

type Key

type Key interface{}

A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators

Jump to

Keyboard shortcuts

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