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