File: api.go

package info (click to toggle)
kitty 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,468 kB
  • sloc: ansic: 84,285; python: 57,992; objc: 5,432; sh: 1,333; xml: 364; makefile: 144; javascript: 78
file content (86 lines) | stat: -rw-r--r-- 1,732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package disk_cache

import (
	"fmt"
	"os"
	"sync"
	"time"
)

var _ = fmt.Print

type Entry struct {
	Key      string
	Size     int64
	LastUsed time.Time
}

type Metadata struct {
	TotalSize     int64
	PathMap       map[string]string
	SortedEntries []*Entry
}

type DiskCache struct {
	Path    string
	MaxSize int64

	lock_file               *os.File
	lock_mutex              sync.Mutex
	entries                 Metadata
	entry_map               map[string]*Entry
	entries_last_read_state *file_state
	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 (dc *DiskCache) ResultsDir() string {
	return dc.get_dir
}

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) Clear() (err error) {
	dc.lock()
	defer dc.unlock()
	return dc.clear()
}

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()
	return dc.add(key, items)
}