cache

package
v1.50.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 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 cahce

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) Put

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

Put puts an value named key into the cache

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