cache

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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