cache

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 7 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

This section is empty.

Types

type Duration

type Duration time.Duration

Duration is a duration that represents the cache duration and some special values -1: never expire 0: never cache

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (interface{}, error)

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(node *yaml.Node) error

type ExpireTime

type ExpireTime int64

ExpireTime in UnixNano

const (
	NeverExpired ExpireTime = -1
)

type FileCache

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

FileCache is a cache that saves to a file

func NewFileCache

func NewFileCache(path string) (*FileCache, error)

NewFileCache creates a new FileCache

func (*FileCache) Close

func (c *FileCache) Close() error

Close the cache and save to file

func (*FileCache) Get

func (c *FileCache) Get(key string) (Value, bool)

Get a value by key

func (*FileCache) Remove

func (c *FileCache) Remove(key string)

Remove a key from the cache

func (*FileCache) Set

func (c *FileCache) Set(key string, value Value, expireTime ExpireTime)

Set a key value pair with a duration

type Item

type Item struct {
	Val    []byte
	Expire int64 // Expire time in UnixNano, -1 means never expire
}

Item is a cache item

type Value

type Value []byte

Value CacheValue is a byte slice that can be unmarshaled into any type

func NewValue

func NewValue(v any) (Value, error)

NewValue marshals the given value into a CacheValue

func (Value) Unmarshal

func (c Value) Unmarshal(v any) error

Unmarshal the CacheValue into the given value

Jump to

Keyboard shortcuts

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