cache

package
v1.0.0-percom23 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoExpiration For use with function that take an expiration time.
	NoExpiration time.Duration = -1
	// DefaultExpiration For use with function 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 = 2 * time.Second
)

Variables

View Source
var (
	DefaultExp      time.Duration = 0 // default expiration
	CleanupInterval time.Duration = 0 //cleanup interval
	Size                          = 0
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}
var (
	Instance *Cache
)

func GetCacheInstance

func GetCacheInstance() *Cache

GetCacheInstance : singleton implementation to retrieve THE cache

func New

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

New 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) Delete

func (c Cache) Delete(k string)

Delete an item from the cache. Does nothing if the key is not in the cache. thread safe

func (Cache) DeleteExpired

func (c Cache) DeleteExpired()

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. Refresh the age parameter.

func (Cache) Set

func (c Cache) Set(k string, x interface{}, d time.Duration)

Set 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. thread safe version

type Item

type Item struct {
	Object     interface{}
	Expiration int64
	Age        int64
	// contains filtered or unexported fields
}

func (*Item) Expired

func (item *Item) Expired() bool

Expired Returns true if the item has expired.

Jump to

Keyboard shortcuts

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