cache

package
v0.0.0-...-94134c1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Key      string
	Data     []byte
	Size     int64
	Accesses int
}

type LRU

type LRU struct {
	MemoryLimit int64
	CurrentMem  int64
	Hits        int64
	Misses      int64
	// contains filtered or unexported fields
}

func NewLRU

func NewLRU(limit int64) *LRU

func (*LRU) Clear

func (c *LRU) Clear()

func (*LRU) Get

func (c *LRU) Get(key string) ([]byte, bool)

func (*LRU) Invalidate

func (c *LRU) Invalidate(key string)

func (*LRU) Set

func (c *LRU) Set(key string, data []byte)

func (*LRU) Stats

func (c *LRU) Stats() (hits, misses int64, size int64)

type ReadaheadCache

type ReadaheadCache struct {
	// contains filtered or unexported fields
}

ReadaheadCache is an LRU cache with read-ahead prefetch capabilities. It monitors sequential read patterns and prefetches upcoming blocks in the background to improve read performance.

func NewReadaheadCache

func NewReadaheadCache(config *ReadaheadConfig) *ReadaheadCache

NewReadaheadCache creates a new readahead cache with the given configuration. If config is nil, DefaultReadaheadConfig() is used.

func (*ReadaheadCache) Clear

func (rc *ReadaheadCache) Clear()

Clear clears all cached data and resets positions.

func (*ReadaheadCache) Close

func (rc *ReadaheadCache) Close()

Close stops the prefetch worker and cleans up resources.

func (*ReadaheadCache) Get

func (rc *ReadaheadCache) Get(key string) ([]byte, bool)

Get retrieves data from the cache and triggers prefetch if sequential access is detected. The key should be formatted as "filename:offset" for readahead to work properly.

func (*ReadaheadCache) GetBlockSize

func (rc *ReadaheadCache) GetBlockSize() int64

GetBlockSize returns the configured block size.

func (*ReadaheadCache) GetPrefetchSize

func (rc *ReadaheadCache) GetPrefetchSize() int

GetPrefetchSize returns the configured prefetch size.

func (*ReadaheadCache) GetWithPrefetch

func (rc *ReadaheadCache) GetWithPrefetch(key string) ([]byte, bool)

GetWithPrefetch retrieves data from cache and triggers prefetch for sequential reads. keyFormat: "filename:offset" - e.g., "data.txt:4096" Returns the cached data and whether it was found.

func (*ReadaheadCache) Invalidate

func (rc *ReadaheadCache) Invalidate(key string)

Invalidate removes a specific key from the cache.

func (*ReadaheadCache) Prefetch

func (rc *ReadaheadCache) Prefetch(file string, offset int64)

Prefetch explicitly prefetches a specific block. This can be called manually when the read pattern is known ahead of time.

func (*ReadaheadCache) Set

func (rc *ReadaheadCache) Set(key string, data []byte)

Set stores data in the cache.

func (*ReadaheadCache) SetPrefetchData

func (rc *ReadaheadCache) SetPrefetchData(key string, data []byte)

SetPrefetchData is called by the prefetch worker to store prefetched data. In a full implementation, this would be used by the background goroutine to store data after reading from disk.

func (*ReadaheadCache) Stats

func (rc *ReadaheadCache) Stats() (hits, misses int64, size int64)

Stats returns cache statistics (hits, misses, current size).

type ReadaheadConfig

type ReadaheadConfig struct {
	// BlockSize is the size of each block in bytes (default: 4KB)
	BlockSize int64
	// PrefetchSize is the number of blocks to prefetch ahead (default: 4)
	PrefetchSize int
	// MemoryLimit is the maximum memory the underlying LRU cache can use
	MemoryLimit int64
}

ReadaheadConfig holds configuration for the readahead cache.

func DefaultReadaheadConfig

func DefaultReadaheadConfig() *ReadaheadConfig

DefaultReadaheadConfig returns a config with default values.

Jump to

Keyboard shortcuts

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