87ff947038
Ensure that clients can use the blob descriptor cache provider without needing the redis package. Signed-off-by: Stephen J Day <stephen.day@docker.com>
35 lines
912 B
Go
35 lines
912 B
Go
// Package cache provides facilities to speed up access to the storage
|
|
// backend.
|
|
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/docker/distribution"
|
|
)
|
|
|
|
// BlobDescriptorCacheProvider provides repository scoped
|
|
// BlobDescriptorService cache instances and a global descriptor cache.
|
|
type BlobDescriptorCacheProvider interface {
|
|
distribution.BlobDescriptorService
|
|
|
|
RepositoryScoped(repo string) (distribution.BlobDescriptorService, error)
|
|
}
|
|
|
|
// ValidateDescriptor provides a helper function to ensure that caches have
|
|
// common criteria for admitting descriptors.
|
|
func ValidateDescriptor(desc distribution.Descriptor) error {
|
|
if err := desc.Digest.Validate(); err != nil {
|
|
return err
|
|
}
|
|
|
|
if desc.Length < 0 {
|
|
return fmt.Errorf("cache: invalid length in descriptor: %v < 0", desc.Length)
|
|
}
|
|
|
|
if desc.MediaType == "" {
|
|
return fmt.Errorf("cache: empty mediatype on descriptor: %v", desc)
|
|
}
|
|
|
|
return nil
|
|
}
|