Documentation
¶
Index ¶
- Constants
- type MemoryCache
- func (mc *MemoryCache) Commit(path string, meta cache.EntryMetadata) error
- func (mc *MemoryCache) Delete(path string) bool
- func (mc *MemoryCache) DeletePartial(path string) bool
- func (mc *MemoryCache) InvalidateRanges(path string) error
- func (mc *MemoryCache) MissingRanges(path string, meta cache.EntryMetadata, requested cache.ByteRange) ([]cache.ByteRange, error)
- func (mc *MemoryCache) Pin(path string)
- func (mc *MemoryCache) PinPartial(path string)
- func (mc *MemoryCache) RangeEntryComplete(path string, meta cache.EntryMetadata) (bool, error)
- func (mc *MemoryCache) RangeMetadata(path string, meta cache.EntryMetadata) (cache.EntryMetadata, bool, error)
- func (mc *MemoryCache) Read(path string, buff []byte, ofst int64) (n int, err error)
- func (mc *MemoryCache) ReadComplete(path string, meta cache.EntryMetadata, buff []byte, ofst int64) (n int, err error)
- func (mc *MemoryCache) ReadPartial(path string, buff []byte, ofst int64) (n int, err error)
- func (mc *MemoryCache) ReadRange(path string, meta cache.EntryMetadata, buff []byte, ofst int64) (int, error)
- func (mc *MemoryCache) StartMaintenance()
- func (mc *MemoryCache) Stats() *cache.Stats
- func (mc *MemoryCache) StopMaintenance()
- func (mc *MemoryCache) Unpin(path string)
- func (mc *MemoryCache) UnpinPartial(path string)
- func (mc *MemoryCache) Write(path string, buff []byte, ofst int64) (int, error)
- func (mc *MemoryCache) WriteCompleteRange(path string, meta cache.EntryMetadata, buff []byte, ofst int64) (int, error)
- func (mc *MemoryCache) WritePartial(path string, buff []byte, ofst int64) (n int, err error)
- func (mc *MemoryCache) WriteRange(path string, meta cache.EntryMetadata, buff []byte, ofst int64) (int, error)
- type Option
Constants ¶
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 ¶
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 (*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) 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 (*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 ¶
WithCapacityBytes sets the maximum total size (in bytes) for the cache.
func WithLogger ¶
WithLogger sets the logger for the cache.
func WithMaintenanceInterval ¶
WithMaintenanceInterval sets the interval for cache maintenance operations.
func WithMaxAge ¶
WithMaxAge sets the maximum age for cache files.
func WithMaxFileCount ¶
WithMaxFileCount sets the maximum number of files for the cache.