tlru

package module
v0.0.0-...-2a1d18c Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: BSD-2-Clause Imports: 5 Imported by: 1

README

go-tlru

An implementation of the Time Aware Least Recent Used (TLRU) caching type for Go.

To start with this library, simply create a new cache with NewCache(MaxLength, MaxBytes int, Duration time.Duration). The first argument specifies the max number of items which can be in the cache, the second argument defines the maximum number of bytes the cache can be (0 means infinite), and the third argument defines how long arguments will last roughly before they are purged. From here, the cache has 2 functions:

  • Get(Key interface{}) (item interface{}, ok bool): Gets the item from the cache by the key interface which was given. The ok boolean defines if it was in the cache and therefore was successfully fetched.
  • Set(Key, Value interface{}): Adds an item with the specified key/value to the cache.

Documentation

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
}

Defines the cache and all required items.

func NewCache

func NewCache(MaxLength, MaxBytes int, Duration time.Duration) *Cache

NewCache is used to create the cache. Setting MaxLength of MaxBytes to 0 will mean unlimited.

func (*Cache) Delete

func (c *Cache) Delete(Key interface{})

Delete is used to delete an option from the cache.

func (*Cache) Erase

func (c *Cache) Erase()

Erase is used to erase the cache.

func (*Cache) Get

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

Get is used to try and get a interface from the cache. The second boolean is meant to represent ok. If it's false, it was not in the cache.

func (*Cache) Set

func (c *Cache) Set(Key, Value interface{})

Set is used to set a key/value interface in the cache.

Jump to

Keyboard shortcuts

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