File: cachestorage.go

package info (click to toggle)
singularity-container 4.1.5%2Bds4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 43,876 kB
  • sloc: asm: 14,840; sh: 3,190; ansic: 1,751; awk: 414; makefile: 413; python: 99
file content (53 lines) | stat: -rw-r--r-- 1,744 bytes parent folder | download | duplicates (3)
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
package solver

import (
	"context"
	"time"

	"github.com/moby/buildkit/session"
	"github.com/moby/buildkit/util/compression"
	digest "github.com/opencontainers/go-digest"
	"github.com/pkg/errors"
)

var ErrNotFound = errors.Errorf("not found")

// CacheKeyStorage is interface for persisting cache metadata
type CacheKeyStorage interface {
	Exists(id string) bool
	Walk(fn func(id string) error) error

	WalkResults(id string, fn func(CacheResult) error) error
	Load(id string, resultID string) (CacheResult, error)
	AddResult(id string, res CacheResult) error
	Release(resultID string) error
	WalkIDsByResult(resultID string, fn func(string) error) error

	AddLink(id string, link CacheInfoLink, target string) error
	WalkLinks(id string, link CacheInfoLink, fn func(id string) error) error
	HasLink(id string, link CacheInfoLink, target string) bool
	WalkBacklinks(id string, fn func(id string, link CacheInfoLink) error) error
}

// CacheResult is a record for a single solve result
type CacheResult struct {
	CreatedAt time.Time
	ID        string
}

// CacheInfoLink is a link between two cache keys
type CacheInfoLink struct {
	Input    Index         `json:"Input,omitempty"`
	Output   Index         `json:"Output,omitempty"`
	Digest   digest.Digest `json:"Digest,omitempty"`
	Selector digest.Digest `json:"Selector,omitempty"`
}

// CacheResultStorage is interface for converting cache metadata result to
// actual solve result
type CacheResultStorage interface {
	Save(Result, time.Time) (CacheResult, error)
	Load(ctx context.Context, res CacheResult) (Result, error)
	LoadRemotes(ctx context.Context, res CacheResult, compression *compression.Config, s session.Group) ([]*Remote, error)
	Exists(ctx context.Context, id string) bool
}