diskcache

package
v0.4.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MmapFile

func MmapFile(f *os.File) ([]byte, error)

MmapFile memory-maps a file for read-only access.

func Munmap

func Munmap(data []byte) error

Munmap unmaps previously mapped memory.

Types

type BlobCacheOptions

type BlobCacheOptions struct {
	// Dir is the directory where cache files are stored.
	Dir string

	// MaxSize is the maximum bytes on disk (default 1GB).
	MaxSize int64

	// MaxItemSize is the maximum size for a single item.
	// Items larger than this will not be cached.
	// Default 0 means no limit.
	MaxItemSize int64
}

BlobCacheOptions configures a BlobCache.

type Cache

type Cache interface {
	Get(key string) ([]byte, bool)
	Set(key string, data []byte) error
	Remove(key string)
	Clear() error
	Stats() Stats
	Close() error
}

Cache is a generic diskcache interface.

func NewBlobCache

func NewBlobCache(opts BlobCacheOptions) (Cache, error)

NewBlobCache creates a new blob cache with the given options.

type FileBackedCache

type FileBackedCache interface {
	RefCountedCache
	CacheDir() string

	// SetFromFile promotes a temp file into the cache under key.
	// tempPath should point to a file on the same filesystem as CacheDir.
	SetFromFile(key, tempPath string, size int64) error
}

type RefCountedCache

type RefCountedCache interface {
	Cache

	// Acquire retrieves data and increments its reference count.
	// The entry will not be evicted until Release is called.
	// Returns the data and true if found, nil and false otherwise.
	Acquire(key string) ([]byte, bool)

	// Release decrements the reference count for an entry.
	// When the count reaches zero, the entry becomes eligible for eviction.
	Release(key string)
}

RefCountedCache extends Cache with reference counting. Reference counting prevents entries from being evicted while in use.

func NewSSTCache

func NewSSTCache(opts SSTCacheOptions) (RefCountedCache, error)

NewSSTCache creates a new SST cache with the given options.

type SSTCacheOptions

type SSTCacheOptions struct {
	Dir string
	// MaxSize is the maximum bytes on disk (default 1GB).
	MaxSize int64
}

SSTCacheOptions configures an SSTCache.

type Stats

type Stats struct {
	Hits       int64
	Misses     int64
	Size       int64
	MaxSize    int64
	EntryCount int
}

Jump to

Keyboard shortcuts

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