cache

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 2 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 {
	Store map[string]*Item
	TTL   time.Duration
	// contains filtered or unexported fields
}

Cache is a simple key value store where the value is always a []byte. It is mostly used in Multikube to store http responses in-memory in order to cache requests and serve content to clients to decrease number of http calls made to upstream servers.

func New

func New() *Cache

New return a new empty cache instance

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes an item by key

func (*Cache) Exists

func (c *Cache) Exists(key string) bool

Exists returns true if an item with the given exists is non-nil. Otherwise returns false

func (*Cache) Get

func (c *Cache) Get(key string) *Item

Get returns an item from the cache by key

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items stored in cache

func (*Cache) ListKeys

func (c *Cache) ListKeys() []string

ListKeys returns the keys of all items in the cache as a string array

func (*Cache) Set

func (c *Cache) Set(key string, val []byte) *Item

Set instantiates and allocates a key in the cache and overwrites any previously set item

func (*Cache) Size

func (c *Cache) Size() int

Size return the sum of all bytes in the cache

type Item

type Item struct {
	Key   string
	Value []byte
	// contains filtered or unexported fields
}

Item represents a unit stored in the cache

func (*Item) Age

func (i *Item) Age() time.Duration

Age returns the duration elapsed since creation

func (*Item) Bytes

func (i *Item) Bytes() int

Bytes returns the number of bytes of i. Shorthand for len(i.Value)

func (*Item) ExpiresAt

func (i *Item) ExpiresAt() time.Time

ExpiresAt return the time when the item was created plus the configured TTL

Jump to

Keyboard shortcuts

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