feat: 添加定时清理图像缓存的功能,以优化内存使用
This commit is contained in:
parent
73ed9bedc9
commit
b9dabbfcb4
@ -15,6 +15,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.lxtend.com/qqbot/util"
|
||||||
"github.com/fogleman/gg"
|
"github.com/fogleman/gg"
|
||||||
"github.com/nfnt/resize"
|
"github.com/nfnt/resize"
|
||||||
"golang.org/x/image/font/opentype"
|
"golang.org/x/image/font/opentype"
|
||||||
@ -25,6 +26,16 @@ var (
|
|||||||
imageCacheLock sync.RWMutex
|
imageCacheLock sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
util.AddCycleTask("bs50_image_cache_cleaner", 10*time.Minute, 10*time.Minute, func() {
|
||||||
|
imageCacheLock.Lock()
|
||||||
|
defer imageCacheLock.Unlock()
|
||||||
|
for k := range imageCache {
|
||||||
|
delete(imageCache, k)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func loadImageFromCache(path string) (image.Image, error) {
|
func loadImageFromCache(path string) (image.Image, error) {
|
||||||
imageCacheLock.RLock()
|
imageCacheLock.RLock()
|
||||||
if img, exists := imageCache[path]; exists {
|
if img, exists := imageCache[path]; exists {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user