cache

package
v4.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

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

This section is empty.

Variables

This section is empty.

Functions

func AddToHash added in v4.6.0

func AddToHash(h uint64, in ...interface{}) uint64

func InitHash added in v4.6.0

func InitHash(t uint64) uint64

func NewHash added in v4.6.0

func NewHash(t uint64, in ...interface{}) uint64

Types

type Cache

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

Cache holds a map of volatile key -> values.

func NewCache

func NewCache() *Cache

NewCache initializes a new caching space with default settings.

func NewCacheWithCapacity

func NewCacheWithCapacity(capacity int) (*Cache, error)

NewCacheWithCapacity initializes a new caching space with the given capacity.

func (*Cache) Clear

func (c *Cache) Clear()

Clear generates a new memory space, leaving the old memory unreferenced, so it can be claimed by the garbage collector.

func (*Cache) Read

func (c *Cache) Read(h Hashable) (string, bool)

Read attempts to retrieve a cached value as a string, if the value does not exists returns an empty string and false.

func (*Cache) ReadRaw

func (c *Cache) ReadRaw(h Hashable) (interface{}, bool)

ReadRaw attempts to retrieve a cached value as an interface{}, if the value does not exists returns nil and false.

func (*Cache) Write

func (c *Cache) Write(h Hashable, value interface{})

Write stores a value in memory. If the value already exists its overwritten.

type HasOnEvict added in v4.6.0

type HasOnEvict interface {
	OnEvict()
}

HasOnEvict type is (optionally) implemented by cache objects to clean after themselves.

type Hashable

type Hashable interface {
	Hash() uint64
}

Hashable types must implement a method that returns a key. This key will be associated with a cached value.

func NewHashable added in v4.6.0

func NewHashable(t uint64, v interface{}) Hashable

Jump to

Keyboard shortcuts

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