Documentation
¶
Overview ¶
Package cache provides caching implementations for RockyardKV.
This package includes an LRU (Least Recently Used) block cache that is used to cache SST file data blocks and index blocks, reducing disk I/O and improving read performance.
Reference: RocksDB v10.7.5
- cache/lru_cache.h
- cache/lru_cache.cc
Index ¶
- type Cache
- type CacheKey
- type Handle
- type LRUCache
- func (c *LRUCache) Close()
- func (c *LRUCache) Erase(key CacheKey)
- func (c *LRUCache) GetCapacity() uint64
- func (c *LRUCache) GetHitCount() uint64
- func (c *LRUCache) GetHitRate() float64
- func (c *LRUCache) GetMissCount() uint64
- func (c *LRUCache) GetOccupancyCount() uint64
- func (c *LRUCache) GetPinnedUsage() uint64
- func (c *LRUCache) GetUsage() uint64
- func (c *LRUCache) Insert(key CacheKey, value []byte, charge uint64) *Handle
- func (c *LRUCache) Lookup(key CacheKey) *Handle
- func (c *LRUCache) Release(handle *Handle)
- func (c *LRUCache) SetCapacity(capacity uint64)
- type ShardedLRUCache
- func (c *ShardedLRUCache) Close()
- func (c *ShardedLRUCache) Erase(key CacheKey)
- func (c *ShardedLRUCache) GetCapacity() uint64
- func (c *ShardedLRUCache) GetHitCount() uint64
- func (c *ShardedLRUCache) GetHitRate() float64
- func (c *ShardedLRUCache) GetMissCount() uint64
- func (c *ShardedLRUCache) GetOccupancyCount() uint64
- func (c *ShardedLRUCache) GetPinnedUsage() uint64
- func (c *ShardedLRUCache) GetUsage() uint64
- func (c *ShardedLRUCache) Insert(key CacheKey, value []byte, charge uint64) *Handle
- func (c *ShardedLRUCache) Lookup(key CacheKey) *Handle
- func (c *ShardedLRUCache) Release(handle *Handle)
- func (c *ShardedLRUCache) SetCapacity(capacity uint64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Insert adds a block to the cache. If the key already exists, it updates the value.
// Returns the handle to the cached block.
Insert(key CacheKey, value []byte, charge uint64) *Handle
// Lookup retrieves a block from the cache.
// Returns nil if not found.
Lookup(key CacheKey) *Handle
// Release releases a handle obtained from Insert or Lookup.
// The caller must call Release when done using the handle.
Release(handle *Handle)
// Erase removes a key from the cache.
Erase(key CacheKey)
// SetCapacity sets the maximum capacity of the cache.
SetCapacity(capacity uint64)
// GetCapacity returns the maximum capacity of the cache.
GetCapacity() uint64
// GetUsage returns the current usage of the cache.
GetUsage() uint64
// GetPinnedUsage returns the usage of currently pinned entries.
GetPinnedUsage() uint64
// GetOccupancyCount returns the number of entries in the cache.
GetOccupancyCount() uint64
// Close releases all resources associated with the cache.
Close()
}
Cache is the interface for all cache implementations.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle represents a reference to a cached block.
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
LRUCache is a thread-safe LRU cache with a fixed capacity.
func NewLRUCache ¶
NewLRUCache creates a new LRU cache with the given capacity in bytes.
func (*LRUCache) GetCapacity ¶
GetCapacity returns the maximum capacity.
func (*LRUCache) GetHitCount ¶
GetHitCount returns the number of cache hits.
func (*LRUCache) GetHitRate ¶
GetHitRate returns the cache hit rate (0.0 to 1.0).
func (*LRUCache) GetMissCount ¶
GetMissCount returns the number of cache misses.
func (*LRUCache) GetOccupancyCount ¶
GetOccupancyCount returns the number of entries.
func (*LRUCache) GetPinnedUsage ¶
GetPinnedUsage returns the usage of currently pinned entries.
func (*LRUCache) SetCapacity ¶
SetCapacity sets the maximum capacity.
type ShardedLRUCache ¶
type ShardedLRUCache struct {
// contains filtered or unexported fields
}
ShardedLRUCache is an LRU cache with multiple shards for reduced lock contention.
func NewShardedLRUCache ¶
func NewShardedLRUCache(capacity uint64, numShards int) *ShardedLRUCache
NewShardedLRUCache creates a new sharded LRU cache. numShards should be a power of 2 for best performance.
func (*ShardedLRUCache) Erase ¶
func (c *ShardedLRUCache) Erase(key CacheKey)
Erase removes a key from the cache.
func (*ShardedLRUCache) GetCapacity ¶
func (c *ShardedLRUCache) GetCapacity() uint64
GetCapacity returns the maximum capacity.
func (*ShardedLRUCache) GetHitCount ¶
func (c *ShardedLRUCache) GetHitCount() uint64
GetHitCount returns the total number of cache hits.
func (*ShardedLRUCache) GetHitRate ¶
func (c *ShardedLRUCache) GetHitRate() float64
GetHitRate returns the overall cache hit rate.
func (*ShardedLRUCache) GetMissCount ¶
func (c *ShardedLRUCache) GetMissCount() uint64
GetMissCount returns the total number of cache misses.
func (*ShardedLRUCache) GetOccupancyCount ¶
func (c *ShardedLRUCache) GetOccupancyCount() uint64
GetOccupancyCount returns the number of entries.
func (*ShardedLRUCache) GetPinnedUsage ¶
func (c *ShardedLRUCache) GetPinnedUsage() uint64
GetPinnedUsage returns the usage of currently pinned entries.
func (*ShardedLRUCache) GetUsage ¶
func (c *ShardedLRUCache) GetUsage() uint64
GetUsage returns the current usage.
func (*ShardedLRUCache) Insert ¶
func (c *ShardedLRUCache) Insert(key CacheKey, value []byte, charge uint64) *Handle
Insert adds a block to the cache.
func (*ShardedLRUCache) Lookup ¶
func (c *ShardedLRUCache) Lookup(key CacheKey) *Handle
Lookup retrieves a block from the cache.
func (*ShardedLRUCache) Release ¶
func (c *ShardedLRUCache) Release(handle *Handle)
Release releases a handle.
func (*ShardedLRUCache) SetCapacity ¶
func (c *ShardedLRUCache) SetCapacity(capacity uint64)
SetCapacity sets the maximum capacity.