// get gets a sorted (by image size) image list from image cache.
// There is a potentical data race in this function. See PR #60448
// Because there is deepcopy function available currently, move sort
// function inside this function
10267
func (i *imageCache) get() []container.Image {
	i.Lock()
	defer i.Unlock()
	sort.Sort(sliceutils.ByImageSize(i.images))
	return i.images
}
359394
func (c *FileCacher) Get(key string) interface{} {
	item, err := c.read(key)
	if err != nil {
		return nil
	}

	if item.hasExpired() {
		os.Remove(c.filepath(key))
		return nil
	}
	return item.Val
}
1237984
func (c *PartitionedLazyCache) Get(partition, key string) (interface{}, error) {
	p, found := c.partitions[partition]

	if !found {
		return nil, nil
	}

	v, found, err := p.Get(key)
	if err != nil {
		return nil, err
	}

	if found {
		return v, nil
	}

	return nil, nil

}
557231
func (c *ContainerCache) Get(svcID string) *docker.Container {
	c.RLock()
	defer c.RUnlock()

	if container, ok := c.cache[svcID]; ok {
		return container
	}

	return nil
}
483925
func (cm *cacheManager) Get(ctx context.Context, id string, opts ...RefOption) (ImmutableRef, error) {
	cm.mu.Lock()
	defer cm.mu.Unlock()
	return cm.get(ctx, id, false, opts...)
}
554049
func (c *attrCache) Get(id uint64) map[string]interface{} {
	c.mu.RLock()
	defer c.mu.RUnlock()
	attrs := c.attrs[id]
	if attrs == nil {
		return nil
	}

	// Make a copy for safety
	ret := make(map[string]interface{})
	for k, v := range attrs {
		ret[k] = v
	}
	return ret
}
1201967
func (cfs *cacheFSObjects) Get(ctx context.Context, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string, opts ObjectOptions) (err error) {
	return cfs.GetObject(ctx, bucket, object, startOffset, length, writer, etag, opts)
}
614751
func (c *Cache) Get(key string) (resp []byte, ok bool) {
	var err error
	resp, err = c.db.Get([]byte(key), nil)
	if err != nil {
		return []byte{}, false
	}
	return resp, true
}
40128
func (c *IgnoreError) Get(key string, params imageserver.Params) (*imageserver.Image, error) {
	im, err := c.Cache.Get(key, params)
	if err != nil {
		return nil, nil
	}
	return im, nil
}
156379
func (m *Memory) Get(offset, size int64) (cpy []byte) {
	if size == 0 {
		return nil
	}

	if len(m.store) > int(offset) {
		cpy = make([]byte, size)
		copy(cpy, m.store[offset:offset+size])

		return
	}

	return
}
554400
func (l *LRUNoTS) Get(key string) (interface{}, error) {
	res, err := l.cache.Get(key)
	if err != nil {
		return nil, err
	}

	elem := res.(*list.Element)
	// move found item to the head
	l.list.MoveToFront(elem)

	return elem.Value.(*kv).v, nil
}
1333240
func (l *SimpleLRUCache) Get(key Key) (value Value, ok bool) {
	element, exists := l.elements[string(key.Hash())]
	if !exists {
		return nil, false
	}
	l.cache.MoveToFront(element)
	return element.Value.(*cacheEntry).value, true
}
118958
func (c *Cacher) Get(key string) map[string]interface{} {
	c.mu.RLock()
	defer c.mu.RUnlock()
	if v, ok := c.data[key]; ok {
		return map[string]interface{}{
			key: v,
		}
	}
	ret := make(map[string]interface{})
	for k, v := range c.data {
		if strings.HasPrefix(k, key) {
			ret[k] = v
		}
	}
	return ret
}
1220779
func (p *MemoryPurse) Get(filename string) (v string, ok bool) {
	p.mu.RLock()
	v, ok = p.files[filename]
	p.mu.RUnlock()
	return
}
1336111
func GetImage(imageName string, includeLayers bool, cacheDir string) (Image, error) {
	logrus.Infof("retrieving image: %s", imageName)
	var img v1.Image
	var err error
	if IsTar(imageName) {
		start := time.Now()
		img, err = tarball.ImageFromPath(imageName, nil)
		if err != nil {
			return Image{}, errors.Wrap(err, "retrieving tar from path")
		}
		elapsed := time.Now().Sub(start)
		logrus.Infof("retrieving image ref from tar took %f seconds", elapsed.Seconds())
	} else if strings.HasPrefix(imageName, daemonPrefix) {
		// remove the daemon prefix
		imageName = strings.Replace(imageName, daemonPrefix, "", -1)

		ref, err := name.ParseReference(imageName, name.WeakValidation)
		if err != nil {
			return Image{}, errors.Wrap(err, "parsing image reference")
		}

		start := time.Now()
		// TODO(nkubala): specify gzip.NoCompression here when functional options are supported
		img, err = daemon.Image(ref, daemon.WithBufferedOpener())
		if err != nil {
			return Image{}, errors.Wrap(err, "retrieving image from daemon")
		}
		elapsed := time.Now().Sub(start)
		logrus.Infof("retrieving local image ref took %f seconds", elapsed.Seconds())
	} else {
		// either has remote prefix or has no prefix, in which case we force remote
		imageName = strings.Replace(imageName, remotePrefix, "", -1)
		ref, err := name.ParseReference(imageName, name.WeakValidation)
		if err != nil {
			return Image{}, errors.Wrap(err, "parsing image reference")
		}
		auth, err := authn.DefaultKeychain.Resolve(ref.Context().Registry)
		if err != nil {
			return Image{}, errors.Wrap(err, "resolving auth")
		}
		start := time.Now()
		img, err = remote.Image(ref, remote.WithAuth(auth), remote.WithTransport(http.DefaultTransport))
		if err != nil {
			return Image{}, errors.Wrap(err, "retrieving remote image")
		}
		elapsed := time.Now().Sub(start)
		logrus.Infof("retrieving remote image ref took %f seconds", elapsed.Seconds())
	}

	// create tempdir and extract fs into it
	var layers []Layer
	if includeLayers {
		start := time.Now()
		imgLayers, err := img.Layers()
		if err != nil {
			return Image{}, errors.Wrap(err, "getting image layers")
		}
		for _, layer := range imgLayers {
			layerStart := time.Now()
			digest, err := layer.Digest()
			path, err := getExtractPathForName(digest.String(), cacheDir)
			if err != nil {
				return Image{
					Layers: layers,
				}, errors.Wrap(err, "getting extract path for layer")
			}
			if err := GetFileSystemForLayer(layer, path, nil); err != nil {
				return Image{
					Layers: layers,
				}, errors.Wrap(err, "getting filesystem for layer")
			}
			layers = append(layers, Layer{
				FSPath: path,
				Digest: digest,
			})
			elapsed := time.Now().Sub(layerStart)
			logrus.Infof("time elapsed retrieving layer: %fs", elapsed.Seconds())
		}
		elapsed := time.Now().Sub(start)
		logrus.Infof("time elapsed retrieving image layers: %fs", elapsed.Seconds())
	}

	imageDigest, err := getImageDigest(img)
	if err != nil {
		return Image{}, err
	}
	path, err := getExtractPathForName(RemoveTag(imageName)+"@"+imageDigest.String(), cacheDir)
	if err != nil {
		return Image{}, err
	}
	// extract fs into provided dir
	if err := GetFileSystemForImage(img, path, nil); err != nil {
		return Image{
			FSPath: path,
			Layers: layers,
		}, errors.Wrap(err, "getting filesystem for image")
	}
	return Image{
		Image:  img,
		Source: imageName,
		FSPath: path,
		Digest: imageDigest,
		Layers: layers,
	}, nil
}
408803
func (c *LFUCache) Get(key interface{}) (interface{}, error) {
	v, err := c.get(key, false)
	if err == KeyNotFoundError {
		return c.getWithLoader(key, true)
	}
	return v, err
}
209017
func (c *Cache) Get(ctx context.Context, key storage.CacheKey) ([]byte, bool) {
	c.mu.Lock()
	defer c.mu.Unlock()

	v, ok := c.cacheMap[key]
	return v, ok
}