File: cache.go

package info (click to toggle)
gitlab-shell 14.35.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,652 kB
  • sloc: ruby: 1,129; makefile: 583; sql: 391; sh: 384
file content (34 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download | duplicates (4)
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
package cache

import (
	"context"
	"io"

	"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
	"google.golang.org/protobuf/proto"
)

// Cache is a stream-oriented cache which stores RPC responses keyed by protobuf requests.
type Cache interface {
	Streamer
	Invalidator
}

// Streamer abstracts away the cache concrete type so that it can be override in tests.
type Streamer interface {
	GetStream(context.Context, *gitalypb.Repository, proto.Message) (io.ReadCloser, error)
	PutStream(context.Context, *gitalypb.Repository, proto.Message, io.Reader) error
}

// Invalidator is able to invalidate parts of the cache pertinent to a
// specific repository. Before a repo mutating operation, StartLease should
// be called. Once the operation is complete, the returned LeaseEnder should
// be invoked to end the lease.
type Invalidator interface {
	StartLease(*gitalypb.Repository) (LeaseEnder, error)
}

// LeaseEnder allows the caller to indicate when a lease is no longer needed
type LeaseEnder interface {
	EndLease(context.Context) error
}