store

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package store defines interfaces to be implemented by cache backends as used by the github.com/bartventer/httpcache package.

Implementing a Cache Backend

To implement a custom cache backend, provide a type that implements the Cache interface.

Implementations must be safe for concurrent use by multiple goroutines.

Implementations can be found in sub-packages such as store/memcache and store/fscache.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotExist = errors.New("cache: entry does not exist")

ErrNotExist is returned when a cache entry does not exist.

Methods such as [Cache.Get] and [Cache.Delete] should return an error that satisfies errors.Is(err, store.ErrNotExist) if the entry is not found.

View Source
var ErrUnknownDriver = errors.New("store: unknown driver")

Functions

func Drivers

func Drivers() []string

Drivers returns a sorted list of the names of the registered drivers.

func Register

func Register(name string, driver Driver)

Register makes a cache implementation available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

Types

type Cache

type Cache interface {
	// Get retrieves the cached value for the given key.
	// If the key does not exist, it should return an error satisfying
	// errors.Is(err, store.ErrNotExist).
	Get(key string) ([]byte, error)

	// Set stores the value for the given key.
	// If the key already exists, it should overwrite the existing value.
	Set(key string, value []byte) error

	// Delete removes the cached value for the given key.
	// If the key does not exist, it should return an error satisfying
	// errors.Is(err, store.ErrNotExist).
	Delete(key string) error
}

Cache describes the interface implemented by types that can store, retrieve, and delete cached values by key.

func Open

func Open(dsn string) (Cache, error)

Open opens a cache using the provided dsn.

type Driver

type Driver interface {
	Open(u *url.URL) (Cache, error)
}

Driver is the interface implemented by cache backends that can create a Cache from a URL. The URL scheme determines which driver is used.

type DriverFunc

type DriverFunc func(u *url.URL) (Cache, error)

DriverFunc is an adapter to allow the use of ordinary functions as Drivers.

func (DriverFunc) Open

func (f DriverFunc) Open(u *url.URL) (Cache, error)

Directories

Path Synopsis
Package acceptancetest provides a suite of acceptance tests for Cache implementations.
Package acceptancetest provides a suite of acceptance tests for Cache implementations.
Package fscache implements a file system-based store.Cache.
Package fscache implements a file system-based store.Cache.
Package memcache provides an in-memory implementation of store.Cache.
Package memcache provides an in-memory implementation of store.Cache.

Jump to

Keyboard shortcuts

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