@@ -25,13 +25,16 @@ import (
25
25
26
26
const lastUsedFileName = ".last-used"
27
27
28
- type buildCache struct {
28
+ // BuildCache represents a cache of built files (sketches and cores), it's designed
29
+ // to work on directories. Given a directory as "base" it handles direct subdirectories as
30
+ // keys
31
+ type BuildCache struct {
29
32
baseDir * paths.Path
30
33
}
31
34
32
35
// GetOrCreate retrieves or creates the cache directory at the given path
33
36
// If the cache already exists the lifetime of the cache is extended.
34
- func (bc * buildCache ) GetOrCreate (key string ) (* paths.Path , error ) {
37
+ func (bc * BuildCache ) GetOrCreate (key string ) (* paths.Path , error ) {
35
38
keyDir := bc .baseDir .Join (key )
36
39
if err := keyDir .MkdirAll (); err != nil {
37
40
return nil , err
@@ -46,7 +49,7 @@ func (bc *buildCache) GetOrCreate(key string) (*paths.Path, error) {
46
49
// Purge removes all cache directories within baseDir that have expired
47
50
// To know how long ago a directory has been last used
48
51
// it checks into the .last-used file.
49
- func (bc * buildCache ) Purge (ttl time.Duration ) {
52
+ func (bc * BuildCache ) Purge (ttl time.Duration ) {
50
53
files , err := bc .baseDir .ReadDir ()
51
54
if err != nil {
52
55
return
@@ -59,8 +62,8 @@ func (bc *buildCache) Purge(ttl time.Duration) {
59
62
}
60
63
61
64
// New instantiates a build cache
62
- func New (baseDir * paths.Path ) * buildCache {
63
- return & buildCache {baseDir }
65
+ func New (baseDir * paths.Path ) * BuildCache {
66
+ return & BuildCache {baseDir }
64
67
}
65
68
66
69
func removeIfExpired (dir * paths.Path , ttl time.Duration ) {
0 commit comments