expirecache

package module
v0.0.0-...-743ef98 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2017 License: BSD-2-Clause Imports: 3 Imported by: 43

README

godoc: https://godoc.org/github.com/dgryski/go-expirecache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Cache is an expiring cache. It is safe for

func New

func New(maxSize uint64) *Cache

New creates a new cache with a maximum memory size

func (*Cache) ApproximateCleaner

func (ec *Cache) ApproximateCleaner(d time.Duration)

ApproximateCleaner starts a goroutine which wakes up periodically and removes a sample of expired items from the cache.

func (*Cache) Cleaner

func (ec *Cache) Cleaner(d time.Duration)

Cleaner starts a goroutine which wakes up periodically and removes all expired items from the cache.

func (*Cache) Get

func (ec *Cache) Get(k string) (item interface{}, ok bool)

Get returns the item from the cache

func (*Cache) GetOrSet

func (ec *Cache) GetOrSet(k string, newValue interface{}, size uint64, expire int32) (item interface{})

GetOrSet returns the item from the cache or sets a new variable if it doesn't exist

func (*Cache) Items

func (ec *Cache) Items() int

Items returns the number of items in the cache

func (*Cache) Set

func (ec *Cache) Set(k string, v interface{}, size uint64, expire int32)

Set adds an item to the cache, with an estimated size and expiration time in seconds.

func (*Cache) Size

func (ec *Cache) Size() uint64

Size returns the current memory size of the cache

func (*Cache) StoppableApproximateCleaner

func (ec *Cache) StoppableApproximateCleaner(d time.Duration, exit <-chan struct{})

Jump to

Keyboard shortcuts

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