mem

package
v3.3.310 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// DefaultCacheCapacity is the maximum size of the cache in bytes if not provided
	// at cache initialization. Equivalent to 1GiB
	DefaultCapacity = 1 << 30

	// MinCapacity is the minimum size of the cache. Equivalent to 256MiB
	MinCapacity = 256 << 20

	// MaxCapacity is the maximum size of the cache. Equivalent to 5GiB
	MaxCapacity = 5 << 30

	// DefaultMaxAge is the maximum age of cache files, if not provided
	// at cache initialization. 0 means no expiration. Equivalent to 12 hours.
	DefaultMaxAge = 12 * time.Hour

	// DefaultMaxFileCount is the maximum number of files in the cache if not provided
	// at cache initialization. 0 means unbounded.
	DefaultMaxFileCount = 1000

	// DefaultMaintenanceInterval is the interval at which cache maintenance tasks are performed,
	// if not provided at cache initialization.
	DefaultMaintenanceInterval = 5 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryCache

type MemoryCache struct {
	Capacity            int64
	MaxFileCount        int64
	MaxAge              time.Duration
	MaintenanceInterval time.Duration
	// contains filtered or unexported fields
}

MemoryCache implements a simple in memory LRU cache for file data with an interface that roughly matches the FUSE Read/Write methods.

TODO:

  • allow concurrent reads/writes to different files in the cache by moving lock coordination out of the caller and lock by path within the cache with a RWMutex map. This will require maintaining a reservation of bytes so that concurrent goroutines can't exhaust memory that a different goroutine evicted for its Write operation.

func NewMemoryCache

func NewMemoryCache(opts ...Option) (*MemoryCache, error)

func (*MemoryCache) Commit added in v3.3.109

func (mc *MemoryCache) Commit(path string, meta cache.EntryMetadata) error

func (*MemoryCache) Delete

func (mc *MemoryCache) Delete(path string) bool

Delete removes the cached file at the given path from the cache.

func (*MemoryCache) DeletePartial added in v3.3.109

func (mc *MemoryCache) DeletePartial(path string) bool

func (*MemoryCache) InvalidateRanges added in v3.3.285

func (mc *MemoryCache) InvalidateRanges(path string) error

InvalidateRanges removes the completed-version identity, including when pinned.

func (*MemoryCache) MissingRanges added in v3.3.285

func (mc *MemoryCache) MissingRanges(path string, meta cache.EntryMetadata, requested cache.ByteRange) ([]cache.ByteRange, error)

MissingRanges returns the requested ranges not present for the remote file version.

func (*MemoryCache) Pin added in v3.2.264

func (mc *MemoryCache) Pin(path string)

Pin increments the reference count for a file, preventing it from being evicted. This should be called when a file handle is opened. Note: MemoryCache uses path directly as the key (same as LRU and files map).

func (*MemoryCache) PinPartial added in v3.3.109

func (mc *MemoryCache) PinPartial(path string)

func (*MemoryCache) RangeEntryComplete added in v3.3.285

func (mc *MemoryCache) RangeEntryComplete(path string, meta cache.EntryMetadata) (bool, error)

RangeEntryComplete reports whether the cached ranges cover the remote file.

func (*MemoryCache) RangeMetadata added in v3.3.285

func (mc *MemoryCache) RangeMetadata(path string, meta cache.EntryMetadata) (cache.EntryMetadata, bool, error)

RangeMetadata returns the validator and coverage belonging to a listing identity.

func (*MemoryCache) Read

func (mc *MemoryCache) Read(path string, buff []byte, ofst int64) (n int, err error)

Read reads data from the cached file at the given path into buff starting at the provided offset.

func (*MemoryCache) ReadComplete added in v3.3.109

func (mc *MemoryCache) ReadComplete(path string, meta cache.EntryMetadata, buff []byte, ofst int64) (n int, err error)

func (*MemoryCache) ReadPartial added in v3.3.109

func (mc *MemoryCache) ReadPartial(path string, buff []byte, ofst int64) (n int, err error)

func (*MemoryCache) ReadRange added in v3.3.285

func (mc *MemoryCache) ReadRange(path string, meta cache.EntryMetadata, buff []byte, ofst int64) (int, error)

ReadRange reads only when every requested byte is valid for the remote file version.

func (*MemoryCache) StartMaintenance

func (mc *MemoryCache) StartMaintenance()

StartMaintenance starts the maintenance goroutine if it is not already running.

func (*MemoryCache) Stats

func (mc *MemoryCache) Stats() *cache.Stats

Stats returns the current cache statistics.

func (*MemoryCache) StopMaintenance

func (mc *MemoryCache) StopMaintenance()

StopMaintenance stops the maintenance goroutine if it is running.

func (*MemoryCache) Unpin added in v3.2.264

func (mc *MemoryCache) Unpin(path string)

Unpin decrements the reference count for a file. When the count reaches zero, the file becomes eligible for eviction. This should be called when a file handle is closed.

func (*MemoryCache) UnpinPartial added in v3.3.109

func (mc *MemoryCache) UnpinPartial(path string)

func (*MemoryCache) Write

func (mc *MemoryCache) Write(path string, buff []byte, ofst int64) (int, error)

func (*MemoryCache) WriteCompleteRange added in v3.3.285

func (mc *MemoryCache) WriteCompleteRange(path string, meta cache.EntryMetadata, buff []byte, ofst int64) (int, error)

WriteCompleteRange uses the same page store as a partial range. It exists so the coordinator can use one contract for dense disk fallback and memory.

func (*MemoryCache) WritePartial added in v3.3.109

func (mc *MemoryCache) WritePartial(path string, buff []byte, ofst int64) (n int, err error)

func (*MemoryCache) WriteRange added in v3.3.285

func (mc *MemoryCache) WriteRange(path string, meta cache.EntryMetadata, buff []byte, ofst int64) (int, error)

WriteRange stores only missing bytes and then publishes their valid ranges.

type Option

type Option func(*MemoryCache)

Option configures a MemoryCache.

func WithCapacityBytes

func WithCapacityBytes(n int64) Option

WithCapacityBytes sets the maximum total size (in bytes) for the cache.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger for the cache.

func WithMaintenanceInterval

func WithMaintenanceInterval(d time.Duration) Option

WithMaintenanceInterval sets the interval for cache maintenance operations.

func WithMaxAge

func WithMaxAge(d time.Duration) Option

WithMaxAge sets the maximum age for cache files.

func WithMaxFileCount

func WithMaxFileCount(n int64) Option

WithMaxFileCount sets the maximum number of files for the cache.

Jump to

Keyboard shortcuts

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