fscache

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: Apache-2.0 Imports: 18 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fscache implements a file system-based cache backend.

Entries are stored as files in a directory under the user's OS cache directory by default. The cache location and behavior are configured via DSN query parameters.

Supported DSN query parameters:

  • appname (required): Subdirectory name for cache isolation.
  • timeout (optional): Operation timeout (e.g., "2s", "500ms"). Default: 5m.
  • connect_timeout (optional): Timeout for establishing the cache connection (e.g., "2s"). Default: 5m.
  • encrypt (optional): Enable encryption for cache entries. Set to "on" or "aesgcm".
  • encrypt_key (optional): The AES key, base64-encoded (URL-safe variant with/without padding as per RFC 4648 §5). Must decode to the correct length as required by crypto/aes.

Example DSNs:

fscache://?appname=myapp
fscache:///tmp/cache?appname=myapp&timeout=2s
fscache:///tmp/cache?appname=myapp&connect_timeout=2s&timeout=1m
fscache://?appname=myapp&encrypt=on&encrypt_key=6S-Ks2YYOW0xMvTzKSv6QD30gZeOi1c6Ydr-As5csWk=

Example environment variable:

export FSCACHE_ENCRYPT_KEY="6S-Ks2YYOW0xMvTzKSv6QD30gZeOi1c6Ydr-As5csWk="

To generate a suitable encryption key (32 bytes, URL-safe, with padding):

openssl rand 32 | base64 | tr '+/' '-_' | tr -d '\n'

Index

Constants

View Source
const Scheme = "fscache" // url scheme for the file system cache

Variables

View Source
var (
	ErrUserCacheDir   = errors.New("fscache: could not determine user cache dir")
	ErrMissingAppName = errors.New("fscache: appname query parameter is required")
	ErrCreateCacheDir = errors.New("fscache: could not create cache dir")
)

Functions

func Open

func Open(appname string, opts ...Option) (*fsCache, error)

Open creates a new file system cache with the specified application name and options.

See the package documentation for supported options and examples.

Types

type Error added in v0.6.0

type Error struct {
	Op  string // operation being performed (e.g., "Get", "Set")
	Key string // optional key for which the operation failed
	Err error  // underlying error
}

func (*Error) Error added in v0.6.0

func (e *Error) Error() string

func (*Error) Unwrap added in v0.6.0

func (e *Error) Unwrap() error

type Option added in v0.6.0

type Option interface {
	// contains filtered or unexported methods
}

func WithBaseDir added in v0.6.0

func WithBaseDir(base string) Option

WithBaseDir sets the base directory for the cache; default: user's OS cache directory.

func WithConnectTimeout added in v0.6.0

func WithConnectTimeout(timeout time.Duration) Option

WithConnectTimeout sets the timeout for establishing the cache connection; default: 5 minutes.

func WithEncryption added in v0.6.0

func WithEncryption(key string) Option

WithEncryption enables encryption for cache entries using AES-GCM.

func WithTimeout added in v0.6.0

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for cache operations; default: 5 minutes.

Jump to

Keyboard shortcuts

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