diskcache

command
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 8 Imported by: 0

README

Disk Cache Example

This example demonstrates using httpcache with persistent disk storage.

Features Demonstrated

  • Creating a disk-based cache
  • Persistent storage across application restarts
  • Cache directory management
  • Multiple clients sharing the same cache

Running the Example

From the project root directory:

go run ./examples/diskcache/main.go

Or from the examples/diskcache directory:

go run main.go

Use Cases

Disk cache is ideal for:

  • Desktop applications - Cache API responses between runs
  • CLI tools - Speed up repeated commands
  • Long-running services - Persist cache across restarts
  • Large datasets - When memory cache would be too large

Configuration

cache := diskcache.New("/path/to/cache/dir")
transport := httpcache.NewTransport(cache)

The disk cache uses the diskv library, which provides:

  • Efficient key-value storage
  • Automatic directory structure
  • Built-in compression support (optional)

Important Notes

  • Cache directory must be writable
  • Files are stored with MD5-hashed filenames
  • No automatic cleanup - consider implementing TTL or size limits
  • Thread-safe for concurrent access

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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