Documentation
¶
Overview ¶
Package disklru implements a disk-based LRU cache.
A small key-value store (powered by kv [1]) keeps track of the keys/size/last access time of each time, and data are stored in files (one file per blob, in nested directory like "blobs/07/077f2cfed67c84d8785515481766669a3a734bd6".
Eviction is triggered when the cache size exceed a limit, it tries to keep the size of the cache under a fixed threshold and remove lest recently used item first.
Index ¶
Data are stored the following way (all the uint32 are binary encoded):
- Index byte + last access time (uint32) + key => size (uint32)
- Keys byte + key => current access time
- MetaCnt byte => number of items currently in the cache (uint32)
- MetaSize byte => total size of the cache (uint32)
Links
[1] https://github.com/cznic/kv
Index ¶
Constants ¶
const ( Keys byte = iota Index MetaSize MetaCnt )
Namespaces for the DB keys
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiskLRU ¶
type DiskLRU struct {
Func func(string, interface{}) ([]byte, error)
MaxSize uint32
sync.Mutex
// contains filtered or unexported fields
}
func New ¶
func New(path string, f func(string, interface{}) ([]byte, error), maxSize uint32) (*DiskLRU, error)
New initialize a new DiskLRU.