GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package cache
  2. import (
  3. "strings"
  4. "time"
  5. "github.com/weaveworks/flux/image"
  6. )
  7. type Reader interface {
  8. // GetKey gets the value at a key, along with its refresh deadline
  9. GetKey(k Keyer) ([]byte, time.Time, error)
  10. }
  11. type Writer interface {
  12. // SetKey sets the value at a key, along with its refresh deadline
  13. SetKey(k Keyer, deadline time.Time, v []byte) error
  14. }
  15. type Client interface {
  16. Reader
  17. Writer
  18. }
  19. // An interface to provide the key under which to store the data
  20. // Use the full path to image for the memcache key because there
  21. // might be duplicates from other registries
  22. type Keyer interface {
  23. Key() string
  24. }
  25. type manifestKey struct {
  26. fullRepositoryPath, reference string
  27. }
  28. func NewManifestKey(image image.CanonicalRef) Keyer {
  29. return &manifestKey{image.CanonicalName().String(), image.Tag}
  30. }
  31. func (k *manifestKey) Key() string {
  32. return strings.Join([]string{
  33. "registryhistoryv3", // Bump the version number if the cache format changes
  34. k.fullRepositoryPath,
  35. k.reference,
  36. }, "|")
  37. }
  38. type repoKey struct {
  39. fullRepositoryPath string
  40. }
  41. func NewRepositoryKey(repo image.CanonicalName) Keyer {
  42. return &repoKey{repo.String()}
  43. }
  44. func (k *repoKey) Key() string {
  45. return strings.Join([]string{
  46. "registryrepov4", // Bump the version number if the cache format changes
  47. k.fullRepositoryPath,
  48. }, "|")
  49. }