Documentation
¶
Overview ¶
Example (Advanced) ¶
Example_advanced demonstrates advanced configuration
package main
import (
"fmt"
"io"
"io/fs"
"os"
"time"
"github.com/absfs/absfs"
"github.com/absfs/cachefs"
)
// Simple in-memory filesystem for examples
type simpleFS struct {
files map[string][]byte
}
func newSimpleFS() *simpleFS {
return &simpleFS{files: make(map[string][]byte)}
}
func (s *simpleFS) Chdir(dir string) error { return nil }
func (s *simpleFS) Getwd() (string, error) { return "/", nil }
func (s *simpleFS) TempDir() string { return "/tmp" }
func (s *simpleFS) Open(name string) (absfs.File, error) { return s.OpenFile(name, os.O_RDONLY, 0) }
func (s *simpleFS) Create(name string) (absfs.File, error) {
return s.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
}
func (s *simpleFS) Mkdir(name string, perm os.FileMode) error { return nil }
func (s *simpleFS) MkdirAll(name string, perm os.FileMode) error { return nil }
func (s *simpleFS) Remove(name string) error { delete(s.files, name); return nil }
func (s *simpleFS) RemoveAll(path string) error { delete(s.files, path); return nil }
func (s *simpleFS) Stat(name string) (os.FileInfo, error) { return nil, os.ErrNotExist }
func (s *simpleFS) Rename(oldname, newname string) error {
s.files[newname] = s.files[oldname]
delete(s.files, oldname)
return nil
}
func (s *simpleFS) Chmod(name string, mode os.FileMode) error { return nil }
func (s *simpleFS) Chtimes(name string, atime time.Time, mtime time.Time) error { return nil }
func (s *simpleFS) Chown(name string, uid, gid int) error { return nil }
func (s *simpleFS) Truncate(name string, size int64) error { return nil }
func (s *simpleFS) OpenFile(name string, flag int, perm os.FileMode) (absfs.File, error) {
return &simpleFile{fs: s, name: name}, nil
}
func (s *simpleFS) ReadDir(name string) ([]fs.DirEntry, error) {
return nil, nil
}
func (s *simpleFS) ReadFile(name string) ([]byte, error) {
data, ok := s.files[name]
if !ok {
return nil, os.ErrNotExist
}
return data, nil
}
func (s *simpleFS) Sub(dir string) (fs.FS, error) {
return absfs.FilerToFS(s, dir)
}
type simpleFile struct {
fs *simpleFS
name string
pos int64
}
func (f *simpleFile) Name() string { return f.name }
func (f *simpleFile) Read(p []byte) (n int, err error) {
data := f.fs.files[f.name]
if f.pos >= int64(len(data)) {
return 0, io.EOF
}
n = copy(p, data[f.pos:])
f.pos += int64(n)
if f.pos >= int64(len(data)) && n < len(p) {
err = io.EOF
}
return
}
func (f *simpleFile) Write(p []byte) (n int, err error) {
f.fs.files[f.name] = append(f.fs.files[f.name], p...)
return len(p), nil
}
func (f *simpleFile) Close() error { return nil }
func (f *simpleFile) Sync() error { return nil }
func (f *simpleFile) Stat() (os.FileInfo, error) { return nil, nil }
func (f *simpleFile) Readdir(int) ([]os.FileInfo, error) { return nil, nil }
func (f *simpleFile) Readdirnames(int) ([]string, error) { return nil, nil }
func (f *simpleFile) ReadDir(int) ([]fs.DirEntry, error) { return nil, nil }
func (f *simpleFile) Seek(offset int64, whence int) (int64, error) { f.pos = offset; return f.pos, nil }
func (f *simpleFile) ReadAt(b []byte, off int64) (n int, err error) {
data := f.fs.files[f.name]
return copy(b, data[off:]), nil
}
func (f *simpleFile) WriteAt(b []byte, off int64) (n int, err error) { return len(b), nil }
func (f *simpleFile) Truncate(size int64) error { return nil }
func (f *simpleFile) WriteString(s string) (n int, err error) { return f.Write([]byte(s)) }
func main() {
backing := newSimpleFS()
// Create cache with custom configuration
cache := cachefs.New(backing,
cachefs.WithWriteMode(cachefs.WriteModeWriteThrough),
cachefs.WithEvictionPolicy(cachefs.EvictionLRU),
cachefs.WithMaxBytes(1024*1024), // 1 MB
cachefs.WithTTL(5*time.Minute),
cachefs.WithMaxEntries(1000),
)
// Use the cache
backing.files["/config.txt"] = []byte("configuration data")
file, _ := cache.OpenFile("/config.txt", os.O_RDONLY, 0644)
data := make([]byte, 18)
file.Read(data)
file.Close()
fmt.Printf("Data: %s\n", string(data))
fmt.Printf("Cache hit rate: %.0f%%\n", cache.Stats().HitRate()*100)
}
Output: Data: configuration data Cache hit rate: 0%
Example (Basic) ¶
Example_basic demonstrates basic usage of cachefs
package main
import (
"fmt"
"io"
"io/fs"
"os"
"time"
"github.com/absfs/absfs"
"github.com/absfs/cachefs"
)
// Simple in-memory filesystem for examples
type simpleFS struct {
files map[string][]byte
}
func newSimpleFS() *simpleFS {
return &simpleFS{files: make(map[string][]byte)}
}
func (s *simpleFS) Chdir(dir string) error { return nil }
func (s *simpleFS) Getwd() (string, error) { return "/", nil }
func (s *simpleFS) TempDir() string { return "/tmp" }
func (s *simpleFS) Open(name string) (absfs.File, error) { return s.OpenFile(name, os.O_RDONLY, 0) }
func (s *simpleFS) Create(name string) (absfs.File, error) {
return s.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
}
func (s *simpleFS) Mkdir(name string, perm os.FileMode) error { return nil }
func (s *simpleFS) MkdirAll(name string, perm os.FileMode) error { return nil }
func (s *simpleFS) Remove(name string) error { delete(s.files, name); return nil }
func (s *simpleFS) RemoveAll(path string) error { delete(s.files, path); return nil }
func (s *simpleFS) Stat(name string) (os.FileInfo, error) { return nil, os.ErrNotExist }
func (s *simpleFS) Rename(oldname, newname string) error {
s.files[newname] = s.files[oldname]
delete(s.files, oldname)
return nil
}
func (s *simpleFS) Chmod(name string, mode os.FileMode) error { return nil }
func (s *simpleFS) Chtimes(name string, atime time.Time, mtime time.Time) error { return nil }
func (s *simpleFS) Chown(name string, uid, gid int) error { return nil }
func (s *simpleFS) Truncate(name string, size int64) error { return nil }
func (s *simpleFS) OpenFile(name string, flag int, perm os.FileMode) (absfs.File, error) {
return &simpleFile{fs: s, name: name}, nil
}
func (s *simpleFS) ReadDir(name string) ([]fs.DirEntry, error) {
return nil, nil
}
func (s *simpleFS) ReadFile(name string) ([]byte, error) {
data, ok := s.files[name]
if !ok {
return nil, os.ErrNotExist
}
return data, nil
}
func (s *simpleFS) Sub(dir string) (fs.FS, error) {
return absfs.FilerToFS(s, dir)
}
type simpleFile struct {
fs *simpleFS
name string
pos int64
}
func (f *simpleFile) Name() string { return f.name }
func (f *simpleFile) Read(p []byte) (n int, err error) {
data := f.fs.files[f.name]
if f.pos >= int64(len(data)) {
return 0, io.EOF
}
n = copy(p, data[f.pos:])
f.pos += int64(n)
if f.pos >= int64(len(data)) && n < len(p) {
err = io.EOF
}
return
}
func (f *simpleFile) Write(p []byte) (n int, err error) {
f.fs.files[f.name] = append(f.fs.files[f.name], p...)
return len(p), nil
}
func (f *simpleFile) Close() error { return nil }
func (f *simpleFile) Sync() error { return nil }
func (f *simpleFile) Stat() (os.FileInfo, error) { return nil, nil }
func (f *simpleFile) Readdir(int) ([]os.FileInfo, error) { return nil, nil }
func (f *simpleFile) Readdirnames(int) ([]string, error) { return nil, nil }
func (f *simpleFile) ReadDir(int) ([]fs.DirEntry, error) { return nil, nil }
func (f *simpleFile) Seek(offset int64, whence int) (int64, error) { f.pos = offset; return f.pos, nil }
func (f *simpleFile) ReadAt(b []byte, off int64) (n int, err error) {
data := f.fs.files[f.name]
return copy(b, data[off:]), nil
}
func (f *simpleFile) WriteAt(b []byte, off int64) (n int, err error) { return len(b), nil }
func (f *simpleFile) Truncate(size int64) error { return nil }
func (f *simpleFile) WriteString(s string) (n int, err error) { return f.Write([]byte(s)) }
func main() {
// Create backing filesystem
backing := newSimpleFS()
// Create cache with default settings (write-through, LRU, 100MB limit)
cache := cachefs.New(backing)
// Write a file
backing.files["/data/file.txt"] = []byte("Hello, CacheFS!")
// Read the file (will be cached)
file, _ := cache.OpenFile("/data/file.txt", os.O_RDONLY, 0644)
data := make([]byte, 15)
n, _ := file.Read(data)
file.Close()
fmt.Printf("Read: %s\n", string(data[:n]))
// Second read will be a cache hit
file2, _ := cache.OpenFile("/data/file.txt", os.O_RDONLY, 0644)
data2 := make([]byte, 15)
file2.Read(data2)
file2.Close()
// Check statistics
stats := cache.Stats()
fmt.Printf("Hits: %d, Misses: %d\n", stats.Hits(), stats.Misses())
}
Output: Read: Hello, CacheFS! Hits: 1, Misses: 1
Example (Eviction) ¶
Example_eviction demonstrates cache eviction
package main
import (
"fmt"
"io"
"io/fs"
"os"
"time"
"github.com/absfs/absfs"
"github.com/absfs/cachefs"
)
// Simple in-memory filesystem for examples
type simpleFS struct {
files map[string][]byte
}
func newSimpleFS() *simpleFS {
return &simpleFS{files: make(map[string][]byte)}
}
func (s *simpleFS) Chdir(dir string) error { return nil }
func (s *simpleFS) Getwd() (string, error) { return "/", nil }
func (s *simpleFS) TempDir() string { return "/tmp" }
func (s *simpleFS) Open(name string) (absfs.File, error) { return s.OpenFile(name, os.O_RDONLY, 0) }
func (s *simpleFS) Create(name string) (absfs.File, error) {
return s.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
}
func (s *simpleFS) Mkdir(name string, perm os.FileMode) error { return nil }
func (s *simpleFS) MkdirAll(name string, perm os.FileMode) error { return nil }
func (s *simpleFS) Remove(name string) error { delete(s.files, name); return nil }
func (s *simpleFS) RemoveAll(path string) error { delete(s.files, path); return nil }
func (s *simpleFS) Stat(name string) (os.FileInfo, error) { return nil, os.ErrNotExist }
func (s *simpleFS) Rename(oldname, newname string) error {
s.files[newname] = s.files[oldname]
delete(s.files, oldname)
return nil
}
func (s *simpleFS) Chmod(name string, mode os.FileMode) error { return nil }
func (s *simpleFS) Chtimes(name string, atime time.Time, mtime time.Time) error { return nil }
func (s *simpleFS) Chown(name string, uid, gid int) error { return nil }
func (s *simpleFS) Truncate(name string, size int64) error { return nil }
func (s *simpleFS) OpenFile(name string, flag int, perm os.FileMode) (absfs.File, error) {
return &simpleFile{fs: s, name: name}, nil
}
func (s *simpleFS) ReadDir(name string) ([]fs.DirEntry, error) {
return nil, nil
}
func (s *simpleFS) ReadFile(name string) ([]byte, error) {
data, ok := s.files[name]
if !ok {
return nil, os.ErrNotExist
}
return data, nil
}
func (s *simpleFS) Sub(dir string) (fs.FS, error) {
return absfs.FilerToFS(s, dir)
}
type simpleFile struct {
fs *simpleFS
name string
pos int64
}
func (f *simpleFile) Name() string { return f.name }
func (f *simpleFile) Read(p []byte) (n int, err error) {
data := f.fs.files[f.name]
if f.pos >= int64(len(data)) {
return 0, io.EOF
}
n = copy(p, data[f.pos:])
f.pos += int64(n)
if f.pos >= int64(len(data)) && n < len(p) {
err = io.EOF
}
return
}
func (f *simpleFile) Write(p []byte) (n int, err error) {
f.fs.files[f.name] = append(f.fs.files[f.name], p...)
return len(p), nil
}
func (f *simpleFile) Close() error { return nil }
func (f *simpleFile) Sync() error { return nil }
func (f *simpleFile) Stat() (os.FileInfo, error) { return nil, nil }
func (f *simpleFile) Readdir(int) ([]os.FileInfo, error) { return nil, nil }
func (f *simpleFile) Readdirnames(int) ([]string, error) { return nil, nil }
func (f *simpleFile) ReadDir(int) ([]fs.DirEntry, error) { return nil, nil }
func (f *simpleFile) Seek(offset int64, whence int) (int64, error) { f.pos = offset; return f.pos, nil }
func (f *simpleFile) ReadAt(b []byte, off int64) (n int, err error) {
data := f.fs.files[f.name]
return copy(b, data[off:]), nil
}
func (f *simpleFile) WriteAt(b []byte, off int64) (n int, err error) { return len(b), nil }
func (f *simpleFile) Truncate(size int64) error { return nil }
func (f *simpleFile) WriteString(s string) (n int, err error) { return f.Write([]byte(s)) }
func main() {
backing := newSimpleFS()
// Small cache that will trigger eviction
cache := cachefs.New(backing,
cachefs.WithMaxBytes(100),
)
// Add files that exceed cache size
backing.files["/file1.txt"] = make([]byte, 60)
backing.files["/file2.txt"] = make([]byte, 60)
// Read first file
file1, _ := cache.OpenFile("/file1.txt", os.O_RDONLY, 0644)
buf1 := make([]byte, 60)
file1.Read(buf1)
file1.Close()
fmt.Printf("Entries after file1: %d\n", cache.Stats().Entries())
// Read second file - should trigger eviction of file1
file2, _ := cache.OpenFile("/file2.txt", os.O_RDONLY, 0644)
buf2 := make([]byte, 60)
file2.Read(buf2)
file2.Close()
fmt.Printf("Entries after file2: %d\n", cache.Stats().Entries())
fmt.Printf("Total evictions: %d\n", cache.Stats().Evictions())
}
Output: Entries after file1: 1 Entries after file2: 1 Total evictions: 1
Index ¶
- func CompareSnapshots(before, after *Snapshot) map[string]int64
- type CacheFS
- func (c *CacheFS) BatchFlush(paths []string) error
- func (c *CacheFS) BatchInvalidate(paths []string) int
- func (c *CacheFS) BatchStats(paths []string) map[string]EntryStats
- func (c *CacheFS) Chdir(dir string) error
- func (c *CacheFS) Chmod(name string, mode fs.FileMode) error
- func (c *CacheFS) Chown(name string, uid, gid int) error
- func (c *CacheFS) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (c *CacheFS) CleanExpired()
- func (c *CacheFS) Clear()
- func (c *CacheFS) Close() error
- func (c *CacheFS) Create(name string) (absfs.File, error)
- func (c *CacheFS) DetailedStats() *DetailedStats
- func (c *CacheFS) ExportJSON() ([]byte, error)
- func (c *CacheFS) ExportPrometheus() string
- func (c *CacheFS) Flush() error
- func (c *CacheFS) GetWarmingProgress() WarmProgress
- func (c *CacheFS) Getwd() (string, error)
- func (c *CacheFS) Invalidate(path string)
- func (c *CacheFS) InvalidatePattern(pattern string) error
- func (c *CacheFS) InvalidatePrefix(prefix string)
- func (c *CacheFS) Mkdir(name string, perm fs.FileMode) error
- func (c *CacheFS) MkdirAll(name string, perm fs.FileMode) error
- func (c *CacheFS) Open(name string) (absfs.File, error)
- func (c *CacheFS) OpenFile(name string, flag int, perm fs.FileMode) (absfs.File, error)
- func (c *CacheFS) Prefetch(paths []string, opts *PrefetchOptions) error
- func (c *CacheFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (c *CacheFS) ReadFile(name string) ([]byte, error)
- func (c *CacheFS) Remove(name string) error
- func (c *CacheFS) RemoveAll(path string) error
- func (c *CacheFS) Rename(oldname, newname string) error
- func (c *CacheFS) ResetStats()
- func (c *CacheFS) Stat(name string) (fs.FileInfo, error)
- func (c *CacheFS) Stats() *Stats
- func (c *CacheFS) Sub(dir string) (fs.FS, error)
- func (c *CacheFS) TakeSnapshot() *Snapshot
- func (c *CacheFS) TempDir() string
- func (c *CacheFS) Truncate(name string, size int64) error
- func (c *CacheFS) WarmCache(paths []string, opts ...WarmOption) error
- func (c *CacheFS) WarmCacheAsync(paths []string, done chan<- error, opts ...WarmOption)
- func (c *CacheFS) WarmCacheFromDir(dir string, opts ...WarmOption) error
- func (c *CacheFS) WarmCacheFromFile(listPath string, opts ...WarmOption) error
- func (c *CacheFS) WarmCacheFromPattern(pattern string, opts ...WarmOption) error
- func (c *CacheFS) WarmCacheFromPatternAsync(pattern string, done chan<- error, opts ...WarmOption)
- func (c *CacheFS) WarmCacheSmart(opts ...WarmOption) error
- type DetailedStats
- type EntryStats
- type EvictionPolicy
- type Option
- func WithEvictionPolicy(policy EvictionPolicy) Option
- func WithFlushInterval(interval time.Duration) Option
- func WithFlushOnClose(enable bool) Option
- func WithMaxBytes(bytes uint64) Option
- func WithMaxEntries(entries uint64) Option
- func WithMetadataCache(enable bool) Option
- func WithMetadataMaxEntries(entries uint64) Option
- func WithTTL(ttl time.Duration) Option
- func WithWriteMode(mode WriteMode) Option
- type PrefetchOptions
- type Snapshot
- type Stats
- type SymlinkCacheFS
- type WarmOption
- type WarmPriority
- type WarmProgress
- type WriteMode
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareSnapshots ¶
CompareSnapshots returns the delta between two snapshots
Types ¶
type CacheFS ¶
type CacheFS struct {
// contains filtered or unexported fields
}
CacheFS is a caching filesystem that wraps another filesystem
func New ¶
func New(backing absfs.FileSystem, opts ...Option) *CacheFS
New creates a new CacheFS with the given backing filesystem and options
func (*CacheFS) BatchFlush ¶
BatchFlush flushes specific dirty entries to the backing store. Returns the first error encountered, but attempts to flush all entries.
func (*CacheFS) BatchInvalidate ¶
BatchInvalidate invalidates multiple paths in a single lock acquisition. Returns the number of entries actually invalidated.
func (*CacheFS) BatchStats ¶
func (c *CacheFS) BatchStats(paths []string) map[string]EntryStats
BatchStats returns statistics for multiple entries in a single lock acquisition. Entries not in cache will have Cached=false.
func (*CacheFS) CleanExpired ¶
func (c *CacheFS) CleanExpired()
CleanExpired removes expired entries (can be called manually or periodically)
func (*CacheFS) DetailedStats ¶
func (c *CacheFS) DetailedStats() *DetailedStats
DetailedStats returns comprehensive statistics about the cache
func (*CacheFS) ExportJSON ¶
ExportJSON exports cache statistics as JSON
func (*CacheFS) ExportPrometheus ¶
ExportPrometheus exports cache statistics in Prometheus format
func (*CacheFS) GetWarmingProgress ¶
func (c *CacheFS) GetWarmingProgress() WarmProgress
GetWarmingProgress returns the current warming progress This is useful when using the Async warming methods
func (*CacheFS) Invalidate ¶
Invalidate removes a specific path from the cache
func (*CacheFS) InvalidatePattern ¶
InvalidatePattern invalidates cache entries matching a glob pattern
func (*CacheFS) InvalidatePrefix ¶
InvalidatePrefix invalidates all cache entries with the given path prefix
func (*CacheFS) Prefetch ¶
func (c *CacheFS) Prefetch(paths []string, opts *PrefetchOptions) error
Prefetch pre-loads multiple files into the cache in parallel. Useful for cache warming scenarios.
func (*CacheFS) TakeSnapshot ¶
TakeSnapshot captures current cache statistics with a timestamp
func (*CacheFS) WarmCache ¶
func (c *CacheFS) WarmCache(paths []string, opts ...WarmOption) error
WarmCache pre-loads a list of files into the cache
func (*CacheFS) WarmCacheAsync ¶
func (c *CacheFS) WarmCacheAsync(paths []string, done chan<- error, opts ...WarmOption)
WarmCacheAsync pre-loads files asynchronously in the background
func (*CacheFS) WarmCacheFromDir ¶
func (c *CacheFS) WarmCacheFromDir(dir string, opts ...WarmOption) error
WarmCacheFromDir recursively loads all files in a directory into cache
func (*CacheFS) WarmCacheFromFile ¶
func (c *CacheFS) WarmCacheFromFile(listPath string, opts ...WarmOption) error
WarmCacheFromFile loads files listed in a text file (one path per line)
func (*CacheFS) WarmCacheFromPattern ¶
func (c *CacheFS) WarmCacheFromPattern(pattern string, opts ...WarmOption) error
WarmCacheFromPattern loads all files matching a glob pattern into cache Note: This requires the backing filesystem to implement a Glob method. If not available, use WarmCache with pre-computed paths instead.
func (*CacheFS) WarmCacheFromPatternAsync ¶
func (c *CacheFS) WarmCacheFromPatternAsync(pattern string, done chan<- error, opts ...WarmOption)
WarmCacheFromPatternAsync loads files matching pattern asynchronously
func (*CacheFS) WarmCacheSmart ¶
func (c *CacheFS) WarmCacheSmart(opts ...WarmOption) error
WarmCacheSmart loads files based on access patterns and frequency This analyzes recent access patterns and pre-loads likely-needed files
type DetailedStats ¶
type DetailedStats struct {
// Basic counters
Hits uint64 `json:"hits"`
Misses uint64 `json:"misses"`
Evictions uint64 `json:"evictions"`
BytesUsed uint64 `json:"bytes_used"`
Entries uint64 `json:"entries"`
// Hit rate
HitRate float64 `json:"hit_rate"`
// Write-back specific
FlushCount uint64 `json:"flush_count,omitempty"`
FlushErrors uint64 `json:"flush_errors,omitempty"`
DirtyEntries uint64 `json:"dirty_entries,omitempty"`
// Per-operation counters
ReadOps uint64 `json:"read_ops,omitempty"`
WriteOps uint64 `json:"write_ops,omitempty"`
InvalidateOps uint64 `json:"invalidate_ops,omitempty"`
// Configuration
MaxBytes uint64 `json:"max_bytes"`
MaxEntries uint64 `json:"max_entries"`
TTL string `json:"ttl,omitempty"`
WriteMode string `json:"write_mode"`
EvictionPolicy string `json:"eviction_policy"`
}
DetailedStats contains comprehensive cache statistics and metrics
type EntryStats ¶
EntryStats contains statistics for a single cache entry
type EvictionPolicy ¶
type EvictionPolicy int
EvictionPolicy defines how entries are evicted when cache is full
const ( // EvictionLRU evicts least recently used entries EvictionLRU EvictionPolicy = iota // EvictionLFU evicts least frequently used entries EvictionLFU // EvictionTTL evicts entries based on time-to-live EvictionTTL // EvictionHybrid combines LRU/LFU with TTL EvictionHybrid )
type Option ¶
type Option func(*CacheFS)
Option is a function that configures a CacheFS
func WithEvictionPolicy ¶
func WithEvictionPolicy(policy EvictionPolicy) Option
WithEvictionPolicy sets the eviction policy for the cache
func WithFlushInterval ¶
WithFlushInterval sets the interval for flushing dirty entries in write-back mode
func WithFlushOnClose ¶
WithFlushOnClose enables flushing dirty entries when files are closed
func WithMaxBytes ¶
WithMaxBytes sets the maximum cache size in bytes
func WithMaxEntries ¶
WithMaxEntries sets the maximum number of cache entries
func WithMetadataCache ¶
WithMetadataCache enables separate metadata caching
func WithMetadataMaxEntries ¶
WithMetadataMaxEntries sets the maximum number of metadata cache entries
func WithWriteMode ¶
WithWriteMode sets the write mode for the cache
type PrefetchOptions ¶
type PrefetchOptions struct {
// Workers is the number of concurrent workers to use for prefetching.
// If 0, defaults to number of CPUs.
Workers int
// SkipErrors continues prefetching even if some files fail to load.
// Errors are still returned but don't stop the operation.
SkipErrors bool
}
PrefetchOptions configures the Prefetch operation
type Snapshot ¶
type Snapshot struct {
Timestamp time.Time
Stats *DetailedStats
}
Snapshot captures a point-in-time view of cache statistics
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Stats represents cache statistics using lock-free atomic operations
type SymlinkCacheFS ¶
type SymlinkCacheFS struct {
*CacheFS
// contains filtered or unexported fields
}
SymlinkCacheFS wraps a SymlinkFileSystem with caching
func NewSymlinkFS ¶
func NewSymlinkFS(backing absfs.SymlinkFileSystem, opts ...Option) *SymlinkCacheFS
NewSymlinkFS creates a new SymlinkCacheFS with the given backing SymlinkFileSystem and options
func (*SymlinkCacheFS) Lchown ¶
func (c *SymlinkCacheFS) Lchown(name string, uid, gid int) error
Lchown changes the owner and group of a symlink
func (*SymlinkCacheFS) Lstat ¶
func (c *SymlinkCacheFS) Lstat(name string) (fs.FileInfo, error)
Lstat returns file info without following symlinks
func (*SymlinkCacheFS) Readlink ¶
func (c *SymlinkCacheFS) Readlink(name string) (string, error)
Readlink returns the destination of a symlink
func (*SymlinkCacheFS) Symlink ¶
func (c *SymlinkCacheFS) Symlink(oldname, newname string) error
Symlink creates a symbolic link
type WarmOption ¶
type WarmOption func(*warmConfig)
WarmOption configures cache warming behavior
func WithWarmPriority ¶
func WithWarmPriority(p WarmPriority) WarmOption
WithWarmPriority sets the priority level for warming
func WithWarmProgress ¶
func WithWarmProgress(fn func(WarmProgress)) WarmOption
WithWarmProgress sets a progress callback for warming
func WithWarmSkipErrors ¶
func WithWarmSkipErrors(skip bool) WarmOption
WithWarmSkipErrors configures whether to skip errors during warming
func WithWarmWorkers ¶
func WithWarmWorkers(n int) WarmOption
WithWarmWorkers sets the number of parallel workers for warming
type WarmPriority ¶
type WarmPriority int
WarmPriority defines the priority level for cache warming
const ( // WarmPriorityHigh loads files first and prevents eviction WarmPriorityHigh WarmPriority = iota // WarmPriorityNormal uses regular cache behavior WarmPriorityNormal // WarmPriorityLow loads only if space available WarmPriorityLow )
type WarmProgress ¶
WarmProgress tracks cache warming progress
type WriteMode ¶
type WriteMode int
WriteMode defines the cache write behavior
const ( // WriteModeWriteThrough writes to both cache and backing store synchronously WriteModeWriteThrough WriteMode = iota // WriteModeWriteBack writes to cache immediately and backing store asynchronously WriteModeWriteBack // WriteModeWriteAround bypasses cache on writes, only caches reads WriteModeWriteAround )