cache

package
v0.0.0-...-d9ac2dc Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(namespace, key string) (string, error)
	Set(namespace, key string, value string) error
	Has(namespace, key string) (bool, error)
	Delete(namespace, key string) error
	Close() error
}

func New

func New(path string) (Cache, error)

New returns a new initialized BadgerDB database implementing the DB interface. If the database cannot be initialized, an error will be returned.

type Db

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

Db is a wrapper around badger.DB

func (*Db) Close

func (c *Db) Close() error

Close implements the DB interface. It closes the connection to the underlying BadgerDB database as well as invoking the context's cancel function.

func (*Db) Delete

func (c *Db) Delete(namespace, key string) error

Delete implements the DB interface. It attempts to delete a value for a given key and namespace. If the key/value pair cannot be deleted, an error is returned.

func (*Db) Get

func (c *Db) Get(namespace, key string) (string, error)

Get implements the DB interface. It attempts to get a value for a given key and namespace. If the key does not exist in the provided namespace, an error is returned, otherwise the retrieved value.

func (*Db) Has

func (c *Db) Has(namespace, key string) (bool, error)

Has implements the DB interface. It returns a boolean reflecting if the database has a given key for a namespace or not. An error is only returned if an error to Get would be returned that is not of type badger.ErrKeyNotFound.

func (*Db) Set

func (c *Db) Set(namespace, key, value string) error

Set implements the DB interface. It attempts to store a value for a given key and namespace. If the key/value pair cannot be saved, an error is returned.

Jump to

Keyboard shortcuts

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