bigcache

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MPL-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package bigcache contains an implementation of the `gokv.Store` interface for BigCache.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Codec: encoding.JSON,
}

DefaultOptions is an Options object with default values. HardMaxCacheSize: 0 (no limit), Eviction: 0 (no limit), Codec: encoding.JSON

Functions

This section is empty.

Types

type Options

type Options struct {
	// The maximum size of the cache in MiB.
	// 0 means no limit.
	// Optional (0 by default, meaning no limit).
	HardMaxCacheSize int
	// Time after which an entry can be evicted.
	// 0 means no eviction.
	// When this is set to 0 and HardMaxCacheSize is set to a non-zero value
	// and the maximum capacity of the cache is reached
	// the oldest entries will be evicted nonetheless when new ones are stored.
	// Optional (0 by default, meaning no eviction).
	Eviction time.Duration
	// Encoding format.
	// Optional (encoding.JSON by default).
	Codec encoding.Codec
}

Options are the options for the BigCache store.

type Store

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

Store is a gokv.Store implementation for BigCache.

func NewStore

func NewStore(options Options) (Store, error)

NewStore creates a BigCache store.

You should call the Close() method on the store when you're done working with it.

func (Store) Close

func (s Store) Close() error

Close closes the store. When called, the cache is left for removal by the garbage collector.

func (Store) Delete

func (s Store) Delete(k string) error

Delete deletes the stored value for the given key. Deleting a non-existing key-value pair does NOT lead to an error. The key must not be "".

func (Store) Get

func (s Store) Get(k string, v any) (found bool, err error)

Get retrieves the stored value for the given key. You need to pass a pointer to the value, so in case of a struct the automatic unmarshalling can populate the fields of the object that v points to with the values of the retrieved object's values. If no value is found it returns (false, nil). The key must not be "" and the pointer must not be nil.

func (Store) Set

func (s Store) Set(k string, v any) error

Set stores the given value for the given key. Values are automatically marshalled to JSON or gob (depending on the configuration). The key must not be "" and the value must not be nil.

Jump to

Keyboard shortcuts

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