cache

package
v0.0.17 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	NoExpiration      time.Duration = -1
	DefaultExpiration time.Duration = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	SetWithExpiration(string, interface{}, time.Duration)
	Set(string, interface{})
	Get(string) (interface{}, bool)
	Delete(string)
	DeleteExpired()
	OnEvicted(func(string, interface{}))
	CloneItems() map[string]Item
	Scan(func([]byte, []byte) error)
	ItemCount() int
}

type CacheMemory

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

func New

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

func NewFrom

func NewFrom(defaultExpiration, cleanupInterval time.Duration, items map[string]Item) *CacheMemory

func (CacheMemory) CloneItems

func (c CacheMemory) CloneItems() map[string]Item

func (CacheMemory) Delete

func (c CacheMemory) Delete(k string)

func (CacheMemory) DeleteExpired

func (c CacheMemory) DeleteExpired()

Delete all expired items from the cache.

func (CacheMemory) Empty

func (c CacheMemory) Empty()

func (CacheMemory) Get

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

func (CacheMemory) ItemCount

func (c CacheMemory) ItemCount() int

func (CacheMemory) OnEvicted

func (c CacheMemory) OnEvicted(f func(string, interface{}))

func (CacheMemory) Scan

func (c CacheMemory) Scan(f func([]byte, []byte) error)

func (CacheMemory) Set

func (c CacheMemory) Set(k string, x interface{})

func (CacheMemory) SetWithExpiration

func (c CacheMemory) SetWithExpiration(k string, x interface{}, d time.Duration)

type Item

type Item struct {
	Object     interface{}
	Expiration int64
}

func (Item) Expired

func (item Item) Expired() bool

Jump to

Keyboard shortcuts

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