cache

package
v0.2.20260510 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cache resolves a safe, OS-appropriate wazero compilation-cache directory for go-googlesql.

go-googlesql ships a ~13 MB wasm module that costs roughly 3 s to compile to native code in CompilationModeCompiler. With a warm cache pointed at a stable on-disk directory, subsequent processes drop their Init() time to ~0.6 s. This package picks that directory using os.UserCacheDir conventions, isolates the cache per linked go-googlesql module version (so a dependency upgrade doesn't try to load stale precompiled wasm), and refuses to write anywhere that could indicate a TOCTOU attack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default() (string, error)

Default returns the canonical wazero cache directory for the current user. The path is keyed by the linked go-googlesql module version so an upgrade gets a fresh cache.

macOS:   ~/Library/Caches/go-googlesql-executequery/wazero/<ver>
Linux:   $XDG_CACHE_HOME/go-googlesql-executequery/wazero/<ver>
         (~/.cache/... when XDG_CACHE_HOME is unset)
Windows: %LocalAppData%/go-googlesql-executequery/wazero/<ver>

func EnsureSafe

func EnsureSafe(dir string) (string, error)

EnsureSafe creates dir (mode 0700) if missing, and refuses to use it if it already exists but is not a regular directory or is a symlink whose target lies outside the user cache root.

Returns the canonical (symlink-resolved) directory on success.

func Resolve

func Resolve(dir string) (string, error)

Resolve returns dir if non-empty, otherwise Default().

func Setup

func Setup(opts ...Option) error

Setup resolves a cache directory, creates it safely, and calls googlesql.Init with WithCompilationCache + WithCompilationMode.

googlesql.Init is sync.Once-guarded so calling Setup more than once is a no-op.

Types

type Option

type Option func(*setupOptions)

Option configures Setup.

func Disable

func Disable() Option

Disable suppresses the on-disk cache. googlesql.Init is still called, in CompilationModeInterpreter (no native compile happens, so no cache is needed).

func WithCompilationMode

func WithCompilationMode(mode googlesql.CompilationMode) Option

WithCompilationMode lets callers override the compilation mode. Default is CompilationModeCompiler.

func WithDir

func WithDir(dir string) Option

WithDir overrides the cache directory. An empty string means "use Default()".

Jump to

Keyboard shortcuts

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