cache

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeCacheBackend

func InitializeCacheBackend(ctx context.Context) (context.Context, error)

func SetCacheBackend

func SetCacheBackend(ctx context.Context, backend Backend) context.Context

Types

type Backend

type Backend interface {
	// Get retrieves cached data for the given key.
	// Returns the data and the timestamp when it was stored.
	// Returns nil data if the key doesn't exist or has expired.
	// Returns error only for actual storage failures (not for cache misses).
	Get(ctx context.Context, key string, maxAge time.Duration) (data []byte, storedAt time.Time, err error)

	// Set stores data in the cache with the given key.
	// The backend should record the current timestamp for expiry checking.
	// url is the original request URL (for visibility/debugging).
	Set(ctx context.Context, key string, data []byte) error

	// Close closes the backend and releases any resources.
	// After Close is called, the backend should not be used.
	Close() error
}

Backend defines the interface for cache storage implementations. Implementations can be filesystem-based, database-based (BigQuery), or any other storage system.

func GetCacheBackend

func GetCacheBackend(ctx context.Context) Backend

type FilesystemBackend

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

FilesystemBackend implements Backend using the local filesystem.

func NewFilesystemBackend

func NewFilesystemBackend(baseDir string) *FilesystemBackend

NewFilesystemBackend creates a new filesystem-based cache backend. baseDir is the root directory for cache storage (typically the outputDir from context).

func (*FilesystemBackend) Close

func (f *FilesystemBackend) Close() error

Close is a no-op for FilesystemBackend as there are no resources to release.

func (*FilesystemBackend) Get

func (f *FilesystemBackend) Get(ctx context.Context, key string, maxAge time.Duration) ([]byte, time.Time, error)

Get retrieves cached data from the filesystem.

func (*FilesystemBackend) Set

func (f *FilesystemBackend) Set(ctx context.Context, key string, data []byte) error

Set stores data in the filesystem cache. url, statusCode, and headers are ignored by the filesystem backend (only used by BigQuery).

Jump to

Keyboard shortcuts

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