cache

package
v0.0.0-...-d31414a Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: MIT Imports: 4 Imported by: 0

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
}

Cache is a typical LRU cache implementation. Once the max size is reached the least recently used data is evicted

func NewCache

func NewCache(capacity int64) *Cache

func (*Cache) Capacity

func (lru *Cache) Capacity() int64

func (*Cache) Clear

func (lru *Cache) Clear()

func (*Cache) Delete

func (lru *Cache) Delete(key string) bool

func (*Cache) Evictions

func (lru *Cache) Evictions() int64

func (*Cache) Get

func (lru *Cache) Get(key string) (v Value, ok bool)

Get, will return the value if present and mark the value as used

func (*Cache) Items

func (lru *Cache) Items() []Item

func (*Cache) Keys

func (lru *Cache) Keys() []string

func (*Cache) Length

func (lru *Cache) Length() int64

func (*Cache) Oldest

func (lru *Cache) Oldest() (oldest time.Time)

func (*Cache) Peek

func (lru *Cache) Peek(key string) (v Value, ok bool)

returns value but doesnt change the priority of eviction for the entry

func (*Cache) Set

func (lru *Cache) Set(key string, value Value)

func (*Cache) SetCapacity

func (lru *Cache) SetCapacity(capacity int64)

func (*Cache) SetIfAbsent

func (lru *Cache) SetIfAbsent(key string, value Value)

func (*Cache) Size

func (lru *Cache) Size() int64

func (*Cache) Stats

func (lru *Cache) Stats() (length, size, capacity, evictions int64, oldest time.Time)

func (*Cache) StatsJSON

func (lru *Cache) StatsJSON() string

type Item

type Item struct {
	Key   string
	Value Value
}

the contract for the intem stored in cache

type Value

type Value interface {
	Size() int
}

Value is the interface values that go into Cache need to satisfy

Jump to

Keyboard shortcuts

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