cache

package
v0.0.0-...-7686319 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// For use with functions that take an expiration time.
	NoExpiration time.Duration = -1
	// For use with functions that take an expiration time. Equivalent to
	// passing in the same expiration duration as was given to New() or
	// NewFrom() when the cache was created (e.g. 5 minutes.)
	DefaultExpiration time.Duration = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func New

func New(defaultExpiration, cleanupInterval time.Duration) *Cache

Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than one (or NoExpiration), the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().

func (*Cache) Count

func (c *Cache) Count() int

Returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up.

func (*Cache) DeleteAll

func (c *Cache) DeleteAll()

DeleteAll removes all items from the cache.

func (*Cache) DeleteExpired

func (c *Cache) DeleteExpired()

Delete all expired items from the cache.

func (*Cache) Get

func (c *Cache) Get(k string) (interface{}, bool)

Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (*Cache) Set

func (c *Cache) Set(key string, val interface{}, d time.Duration)

Add an item to the cache, replacing any existing item. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.

func (*Cache) SetWithDefaultExp

func (c *Cache) SetWithDefaultExp(k string, x interface{})

Add an item to the cache, replacing any existing item, using the default expiration.

type LRUCache

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

LRUCache is a LRU cache.

func NewLRU

func NewLRU(maxItems int64) *LRUCache

New is the Constructor of Cache

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (interface{}, bool)

Get returns a value from cache

func (*LRUCache) Put

func (c *LRUCache) Put(key string, val interface{})

Put adds a value to the cache.

type LRUCacher

type LRUCacher interface {
	Put(key string, val interface{})
	Get(key string) (interface{}, bool)
}

LRUCacher is a LRU cache interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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