mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-19 15:04:50 +02:00
disk cache: add a path based API
This allows maintaining only a single cache entry per path when the path's contents change.
This commit is contained in:
@@ -17,6 +17,7 @@ type Entry struct {
|
||||
|
||||
type Metadata struct {
|
||||
TotalSize int64
|
||||
PathMap map[string]string
|
||||
SortedEntries []*Entry
|
||||
}
|
||||
|
||||
@@ -29,29 +30,45 @@ type DiskCache struct {
|
||||
entries Metadata
|
||||
entry_map map[string]*Entry
|
||||
entries_mod_time time.Time
|
||||
entries_dirty bool
|
||||
get_dir string
|
||||
read_count int
|
||||
}
|
||||
|
||||
func NewDiskCache(path string, max_size int64) (dc *DiskCache, err error) {
|
||||
return new_disk_cache(path, max_size)
|
||||
}
|
||||
|
||||
func KeyForPath(path string) (key string, err error) {
|
||||
return key_for_path(path)
|
||||
}
|
||||
|
||||
func (dc *DiskCache) Get(key string, items ...string) map[string]string {
|
||||
func (dc *DiskCache) Get(key string, items ...string) (map[string]string, error) {
|
||||
dc.lock()
|
||||
defer dc.unlock()
|
||||
return dc.get(key, items)
|
||||
}
|
||||
|
||||
func (dc *DiskCache) GetPath(path string, items ...string) (string, map[string]string, error) {
|
||||
dc.lock()
|
||||
defer dc.unlock()
|
||||
key, err := key_for_path(path)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
ans, err := dc.get(key, items)
|
||||
return key, ans, err
|
||||
}
|
||||
|
||||
func (dc *DiskCache) Remove(key string) (err error) {
|
||||
dc.lock()
|
||||
defer dc.unlock()
|
||||
return dc.remove(key)
|
||||
}
|
||||
|
||||
func (dc *DiskCache) AddPath(path, key string, items map[string][]byte) (ans map[string]string, err error) {
|
||||
dc.lock()
|
||||
defer dc.unlock()
|
||||
ans, err = dc.add_path(path, key, items)
|
||||
return
|
||||
}
|
||||
|
||||
func (dc *DiskCache) Add(key string, items map[string][]byte) (ans map[string]string, err error) {
|
||||
dc.lock()
|
||||
defer dc.unlock()
|
||||
|
||||
Reference in New Issue
Block a user