localfs

package module
v0.0.0-...-5aa709d Latest Latest
Warning

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

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

README

persist/localfs

Local filesystem persistence using Go's gob encoding.

Features

  • Zero dependencies beyond stdlib
  • Automatic directory management
  • Per-item file storage for crash safety
  • Buffered I/O for performance
  • Works across all platforms

Usage

import (
    "github.com/codeGROOVE-dev/bdcache"
    "github.com/codeGROOVE-dev/bdcache/persist/localfs"
)

// Uses OS cache directory (e.g., ~/.cache/myapp on Linux)
p, _ := localfs.New[string, User]("myapp", "")

// Or specify custom directory
p, _ := localfs.New[string, User]("myapp", "/tmp/my-cache")

cache, _ := bdcache.New[string, User](ctx,
    bdcache.WithPersistence(p))

Storage Location

Files are stored in subdirectories based on key hash to avoid filesystem limits:

  • Linux/macOS: ~/.cache/myapp/XX/key
  • Windows: %LocalAppData%\myapp\XX\key

Where XX is the first 2 hex digits of the key's hash.

Key Constraints

  • Maximum key length: 127 characters
  • Keys are sanitized for filesystem safety
  • No path traversal sequences allowed

Documentation

Overview

Package localfs provides local filesystem persistence for bdcache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[K comparable, V any](cacheID string, dir string) (bdcache.PersistenceLayer[K, V], error)

New creates a new file-based persistence layer. The cacheID is used as a subdirectory name under the OS cache directory. If dir is provided (non-empty), it's used as the base directory instead of OS cache dir. This is useful for testing with temporary directories.

Types

This section is empty.

Jump to

Keyboard shortcuts

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