cache

package
v0.0.107 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 3 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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