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
}
|