-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathcache.go
52 lines (43 loc) · 2.02 KB
/
cache.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
// Copyright 2017 GRAIL, Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package reflow
import (
"context"
"github.com/grailbio/base/digest"
)
// A Cache stores Values and their associated File objects for later
// retrieval. Caches may be temporary: objects are not guaranteed
// to persist.
type Cache interface {
// Lookup returns the value associated with a (digest) key.
// Lookup returns an error flagged errors.NotExist when there
// is no such value.
//
// Lookup should also check to make sure that the objects
// actually exist, and provide a reasonable guarantee that they'll
// be available for transfer.
//
// TODO(marius): allow the caller to maintain a lease on the desired
// objects so that garbage collection can (safely) be run
// concurrently with flows. This isn't a correctness concern (the
// flows may be restarted), but rather one of efficiency.
Lookup(context.Context, digest.Digest) (Fileset, error)
// Transfer transmits the file objects associated with value v
// (usually retrieved by Lookup) to the repository dst. Transfer
// should be used in place of direct (cache) repository access since
// it may apply additional policies (e.g., rate limiting, etc.)
Transfer(ctx context.Context, dst Repository, v Fileset) error
// NeedTransfer returns the set of files in the Fileset v that are absent
// in the provided repository.
NeedTransfer(ctx context.Context, dst Repository, v Fileset) ([]File, error)
// Write stores the Value v, whose file objects exist in Repository repo,
// under the key id. If the repository is nil no objects are transferred.
Write(ctx context.Context, id digest.Digest, v Fileset, repo Repository) error
// Delete removes the value named by id from this cache.
Delete(ctx context.Context, id digest.Digest) error
// Repository returns this cache's underlying repository. It should
// not be used for data transfer during the course of evaluation; see
// Transfer.
Repository() Repository
}