6 Star 67 Fork 14

楠木 / orly

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
imagecache.go 863 Bytes
一键复制 编辑 原始数据 按行查看 历史
楠木 提交于 2018-09-28 00:40 . [dev] image cache
/*
* Copyright (c) 2018 LI Zhennan
*
* Use of this work is governed by an MIT License.
* You may find a license copy in project root.
*
*/
package orly
import (
"image"
"sync"
)
// ImageCache is an in-memory key-value image store
//
// ImageCache is safe for concurrency use.
type ImageCache struct {
m sync.Map
}
// NewImageCache returns a empty image store
func NewImageCache() *ImageCache {
return new(ImageCache)
}
// Store sets the image for a key.
func (i *ImageCache) Store(key string, img image.Image) {
i.m.Store(key, img)
}
// Load returns the image stored in the map for a key,
// or nil if no value is present.
//
// The found result indicates whether value was found in the map.
func (i *ImageCache) Load(key string) (img image.Image, found bool) {
thing, found := i.m.Load(key)
if found {
img = thing.(image.Image)
}
return
}
Go
1
https://gitee.com/nanmu42/orly.git
git@gitee.com:nanmu42/orly.git
nanmu42
orly
orly
master

搜索帮助