Documentation
¶
Index ¶
- type Entry
- type LRU
- type ReadaheadCache
- func (rc *ReadaheadCache) Clear()
- func (rc *ReadaheadCache) Close()
- func (rc *ReadaheadCache) Get(key string) ([]byte, bool)
- func (rc *ReadaheadCache) GetBlockSize() int64
- func (rc *ReadaheadCache) GetPrefetchSize() int
- func (rc *ReadaheadCache) GetWithPrefetch(key string) ([]byte, bool)
- func (rc *ReadaheadCache) Invalidate(key string)
- func (rc *ReadaheadCache) Prefetch(file string, offset int64)
- func (rc *ReadaheadCache) Set(key string, data []byte)
- func (rc *ReadaheadCache) SetPrefetchData(key string, data []byte)
- func (rc *ReadaheadCache) Stats() (hits, misses int64, size int64)
- type ReadaheadConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRU ¶
type LRU struct {
MemoryLimit int64
CurrentMem int64
Hits int64
Misses int64
// contains filtered or unexported fields
}
func (*LRU) Invalidate ¶
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.