forked from golang/dep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_cache_multi.go
120 lines (96 loc) · 2.64 KB
/
source_cache_multi.go
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gps
import (
"github.com/golang/dep/internal/gps/pkgtree"
)
// A multiCache manages two cache levels, ephemeral in-memory and persistent on-disk.
//
// The in-memory cache is always checked first, with the on-disk used as a fallback.
// Values read from disk are set in-memory when an appropriate method exists.
//
// Set values are cached both in-memory and on-disk.
type multiCache struct {
mem, disk singleSourceCache
}
func (c *multiCache) setManifestAndLock(r Revision, ai ProjectAnalyzerInfo, m Manifest, l Lock) {
c.mem.setManifestAndLock(r, ai, m, l)
c.disk.setManifestAndLock(r, ai, m, l)
}
func (c *multiCache) getManifestAndLock(r Revision, ai ProjectAnalyzerInfo) (Manifest, Lock, bool) {
m, l, ok := c.mem.getManifestAndLock(r, ai)
if ok {
return m, l, true
}
m, l, ok = c.disk.getManifestAndLock(r, ai)
if ok {
c.mem.setManifestAndLock(r, ai, m, l)
return m, l, true
}
return nil, nil, false
}
func (c *multiCache) setPackageTree(r Revision, ptree pkgtree.PackageTree) {
c.mem.setPackageTree(r, ptree)
c.disk.setPackageTree(r, ptree)
}
func (c *multiCache) getPackageTree(r Revision) (pkgtree.PackageTree, bool) {
ptree, ok := c.mem.getPackageTree(r)
if ok {
return ptree, true
}
ptree, ok = c.disk.getPackageTree(r)
if ok {
c.mem.setPackageTree(r, ptree)
return ptree, true
}
return pkgtree.PackageTree{}, false
}
func (c *multiCache) markRevisionExists(r Revision) {
c.mem.markRevisionExists(r)
c.disk.markRevisionExists(r)
}
func (c *multiCache) setVersionMap(pvs []PairedVersion) {
c.mem.setVersionMap(pvs)
c.disk.setVersionMap(pvs)
}
func (c *multiCache) getVersionsFor(rev Revision) ([]UnpairedVersion, bool) {
uvs, ok := c.mem.getVersionsFor(rev)
if ok {
return uvs, true
}
return c.disk.getVersionsFor(rev)
}
func (c *multiCache) getAllVersions() ([]PairedVersion, bool) {
pvs, ok := c.mem.getAllVersions()
if ok {
return pvs, true
}
pvs, ok = c.disk.getAllVersions()
if ok {
c.mem.setVersionMap(pvs)
return pvs, true
}
return nil, false
}
func (c *multiCache) getRevisionFor(uv UnpairedVersion) (Revision, bool) {
rev, ok := c.mem.getRevisionFor(uv)
if ok {
return rev, true
}
return c.disk.getRevisionFor(uv)
}
func (c *multiCache) toRevision(v Version) (Revision, bool) {
rev, ok := c.mem.toRevision(v)
if ok {
return rev, true
}
return c.disk.toRevision(v)
}
func (c *multiCache) toUnpaired(v Version) (UnpairedVersion, bool) {
uv, ok := c.mem.toUnpaired(v)
if ok {
return uv, true
}
return c.disk.toUnpaired(v)
}