cache

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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