cache

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertIDtoFileName

func ConvertIDtoFileName(dbFileDir, identifier string) string

ConvertIDtoFileName converts a ID string into a filename string by replacing several characters

Types

type BoltMetaDB

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

BoltMetaDB is a single boltDB with multiple internal "buckets" for each URL (like tables)

func NewBoltMetaDB

func NewBoltMetaDB(logger *slog.Logger, dbFileDir string) (*BoltMetaDB, error)

NewBoltMetaDB creates a new BoltMetaDB object, to load or create a new boltDB on disk

func (*BoltMetaDB) Close

func (c *BoltMetaDB) Close() error

Close closes all the BadgerDBs in the collection

func (*BoltMetaDB) Get

func (c *BoltMetaDB) Get(identifier string, body []byte) (response *schema.ProxyResponse, err error)

Get receives a request, pulls out the request URL, uses that URL as a cache "identifier" (to use the correct storage DB), and then looks up the request in cache based on the body, returning the cached response if found.

The request URL can be considered the primary index (different files per URL), and the body is the secondary index.

func (*BoltMetaDB) Len

func (c *BoltMetaDB) Len(identifier string) (int, error)

len return the number of items currently in the cache

func (*BoltMetaDB) Put

func (c *BoltMetaDB) Put(request *schema.ProxyRequest, response *schema.ProxyResponse) error

Put receives a request and response, pulls out the request URL, uses that URL as a cache "identifier" (to use the correct storage DB), and then stores the response in cache based on the request body.

type DB

type DB interface {
	Close() error
	Len(identifier string) (int, error)
	Get(identifier string, body []byte) (response *schema.ProxyResponse, err error)
	Put(request *schema.ProxyRequest, response *schema.ProxyResponse) error
}

type MemoryMetaDB added in v2.4.0

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

func NewMemoryMetaDB added in v2.4.0

func NewMemoryMetaDB(logger *slog.Logger, maxEntries int) (*MemoryMetaDB, error)

NewMemoryMetaDB creates a new MemoryMetaDB object

func (*MemoryMetaDB) Close added in v2.4.0

func (c *MemoryMetaDB) Close() error

func (*MemoryMetaDB) Get added in v2.4.0

func (c *MemoryMetaDB) Get(identifier string, body []byte) (response *schema.ProxyResponse, err error)

func (*MemoryMetaDB) Len added in v2.4.0

func (c *MemoryMetaDB) Len(identifier string) (int, error)

func (*MemoryMetaDB) Put added in v2.4.0

func (c *MemoryMetaDB) Put(request *schema.ProxyRequest, response *schema.ProxyResponse) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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