cache

package
v1.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(v interface{}) string

Hash computes the hash of the given object.

Types

type Hashable

type Hashable interface {
	// Hash returns the computed hash of the object.
	Hash() string
}

Hashable represents an object that can compute a hash.

type LRU

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

LRU is an LRU cache implementation.

func NewLRU

func NewLRU(opts ...Options) *LRU

NewLRU creates and returns a new LRU cache.

func (*LRU) Get

func (c *LRU) Get(h Hashable) (string, bool)

Get attempts to retrieve a cached value as a string. It returns false if the value does not exist or cannot be type-casted to a string.

func (*LRU) Set

func (c *LRU) Set(h Hashable, v interface{})

Set stores the given value to the cache.

type Options

type Options struct {
	// Capacity is the number of items to hold before evicting. Default is 128.
	Capacity int
}

Options contains options for creating an LRU cache.

Jump to

Keyboard shortcuts

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