badgerdriver

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package badgerdriver provides a Badger-backed embedded implementation of the framework's cache.Cache interface (Has/Get/Set/Forget/EmptyByMatch/Empty).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadgerCacheClean

func BadgerCacheClean(cache *BadgerCache) error

BadgerCacheClean runs Badger's value-log garbage collection to reclaim disk space from deleted data, keeping the database size under control.

func CreateBadgerPool

func CreateBadgerPool(storagePath string) *badger.DB

CreateBadgerPool opens (or creates) a Badger database at the given storage path with logging disabled. Returns the opened *badger.DB, or nil if the database cannot be opened.

Types

type BadgerCache

type BadgerCache struct {
	Conn   *badger.DB
	Prefix string
}

BadgerCache is a cache.Cache implementation backed by an embedded Badger key-value store. Conn holds the open *badger.DB connection used for all read and write transactions, and Prefix is an optional namespace applied to keys managed by this cache.

func (*BadgerCache) Empty

func (b *BadgerCache) Empty() error

Empty deletes all keys in the cache, delegating to emptyByMatch with an empty prefix that matches everything.

func (*BadgerCache) EmptyByMatch

func (b *BadgerCache) EmptyByMatch(str string) error

EmptyByMatch deletes all keys with the given prefix, delegating to emptyByMatch.

func (*BadgerCache) Forget

func (b *BadgerCache) Forget(str string) error

Forget deletes a single key from the cache inside a Badger write transaction (Update).

func (*BadgerCache) Get

func (b *BadgerCache) Get(str string) (interface{}, error)

Get reads the raw bytes stored for a key inside a Badger read transaction (View) and decodes the stored entry. The decoded entry is a map keyed by the cache key, from which the value for str is extracted and returned. Returns an error if the key is missing or if reading or decoding the stored bytes fails.

func (*BadgerCache) Has

func (b *BadgerCache) Has(str string) (bool, error)

Has reports whether a key exists in the cache by attempting to Get it.

func (*BadgerCache) Set

func (b *BadgerCache) Set(str string, value interface{}, expires ...int) error

Set encodes a value and stores it under the given key inside a Badger write transaction (Update). The variadic expires argument is a TTL in seconds applied via WithTTL when supplied; otherwise the entry has no expiry. Returns an error if encoding the value fails.

Jump to

Keyboard shortcuts

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