cache

package
v0.0.0-...-667c717 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2016 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package cache implements a simple time-outable cache

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeoutExpired is the error returned along with the value when the timeout
	// for the value has expired
	ErrTimeoutExpired = errors.New("timeout expired, value may be invalid now")
	// ErrWrongType is the error returned when the value could not be typecast
	// into the requested type
	ErrWrongType = errors.New("the value does not conform to the requested type")
)

Functions

This section is empty.

Types

type Cache

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

Cache represents a simple safe

func NewCache

func NewCache() *Cache

NewCache creates a new Cache and returns a pointer to it

func (*Cache) Clear

func (c *Cache) Clear(k string)

Clear deletes the value of the cache for key k and its associated timeout

func (*Cache) Read

func (c *Cache) Read(k string) (interface{}, error)

ReadCache returns the value of the cache for key k. If the value has expeired, it also returns the ErrTimeoutExpired error

func (*Cache) ReadString

func (c *Cache) ReadString(k string) (string, error)

ReadString returns the value of the cache for key k typecast into a string. If it cannot be typecast, it will return ErrWrongType. The method will return an ErrTimeoutExpired if appropriate and the typecast succeeded

func (*Cache) Write

func (c *Cache) Write(k string, v interface{})

Write sets the value of the cache to v for key k. It also clears the expiration time for the key, if it existed

func (*Cache) WriteTimeout

func (c *Cache) WriteTimeout(k string, v interface{}, e time.Duration)

WriteTimeout sets the value of the cache to v for key k. It sets the expiration time for the key to now + e

Jump to

Keyboard shortcuts

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