cache.go 908 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Package cache provides facilities to speed up access to the storage
  2. // backend.
  3. package cache
  4. import (
  5. "fmt"
  6. "github.com/docker/distribution"
  7. )
  8. // BlobDescriptorCacheProvider provides repository scoped
  9. // BlobDescriptorService cache instances and a global descriptor cache.
  10. type BlobDescriptorCacheProvider interface {
  11. distribution.BlobDescriptorService
  12. RepositoryScoped(repo string) (distribution.BlobDescriptorService, error)
  13. }
  14. // ValidateDescriptor provides a helper function to ensure that caches have
  15. // common criteria for admitting descriptors.
  16. func ValidateDescriptor(desc distribution.Descriptor) error {
  17. if err := desc.Digest.Validate(); err != nil {
  18. return err
  19. }
  20. if desc.Size < 0 {
  21. return fmt.Errorf("cache: invalid length in descriptor: %v < 0", desc.Size)
  22. }
  23. if desc.MediaType == "" {
  24. return fmt.Errorf("cache: empty mediatype on descriptor: %v", desc)
  25. }
  26. return nil
  27. }