cache

package
v1.52.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: MIT Imports: 2 Imported by: 8

Documentation

Overview

Package cache implements a simple cache where the entries are expired after a given time (5 minutes of disuse by default).

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 holds values indexed by string, but expired after a given (5 minutes by default).

func New

func New() *Cache

New creates a new cache with the default expire duration and interval

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes everything from the cache

func (*Cache) Entries

func (c *Cache) Entries() int

Entries returns the number of entries in the cache

func (*Cache) Get

func (c *Cache) Get(key string, create CreateFunc) (value interface{}, err error)

Get gets a value named key either from the cache or creates it afresh with the create function.

func (*Cache) GetMaybe

func (c *Cache) GetMaybe(key string) (value interface{}, found bool)

GetMaybe returns the key and true if found, nil and false if not

func (*Cache) Pin added in v1.52.0

func (c *Cache) Pin(key string)

Pin a value in the cache if it exists

func (*Cache) Put

func (c *Cache) Put(key string, value interface{})

Put puts a value named key into the cache

func (*Cache) Rename added in v1.52.0

func (c *Cache) Rename(oldKey, newKey string) (value interface{}, found bool)

Rename renames the item at oldKey to newKey.

If there was an existing item at newKey then it takes precedence and is returned otherwise the item (if any) at oldKey is returned.

func (*Cache) Unpin added in v1.52.0

func (c *Cache) Unpin(key string)

Unpin a value in the cache if it exists

type CreateFunc

type CreateFunc func(key string) (value interface{}, ok bool, error error)

CreateFunc is called to create new values. If the create function returns an error it will be cached if ok is true, otherwise the error will just be returned, allowing negative caching if required.

Jump to

Keyboard shortcuts

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