cache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright 2022-2026 Reto Gantenbein SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig struct {
	// Local file system base path for storing cached files
	BasePath string

	// List of file suffixes that will be cached
	FileSuffixes []string
}

type FileCache

type FileCache interface {
	// Create a temp file in the cache directory for the given URI, suitable
	// for streaming writes. Creates parent directories and validates path
	// traversal. The caller is responsible for closing the returned file.
	CreateTempWriter(uri string) (*os.File, error)

	// Atomically commit a temp file into the cache by setting its mtime
	// and renaming it to the final path for the given URI. Trusts that
	// the URI was already validated by CreateTempWriter.
	CommitTempFile(tmpPath string, uri string, mtime time.Time) error

	// Remove cached file for given URL
	DeleteFile(string) error

	// Return file system path to cached file for given URL. If the URL points
	// to a path outside the cache directory return an error.
	GetFilePath(string) (string, error)

	// Returns a list of file suffixes that will be cached
	GetFileSuffixes() []string

	// Return if URL is supposed to be cached
	IsCacheCandidate(string) bool

	// Return if file exists in cache for given URL
	IsCached(string) bool

	// Save buffer as file in cache for given URL
	SaveToDisk(string, *bytes.Buffer, time.Time) error
}

func New

func New(cfg *CacheConfig) FileCache

Jump to

Keyboard shortcuts

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