27 lines
613 B
Go
27 lines
613 B
Go
package help
|
|
|
|
import (
|
|
"mini_server/internal/dao"
|
|
"time"
|
|
|
|
"github.com/patrickmn/go-cache"
|
|
)
|
|
|
|
// 添加文件缓存功能,将文件数据保存到内存中,减少与数据库的交互,提高性能。
|
|
var fileCache *cache.Cache
|
|
|
|
func init() {
|
|
fileCache = cache.New(time.Hour, time.Minute*30) // 设置超时时间和清理时间
|
|
}
|
|
|
|
func GetFileCache(file_uuid string) (*dao.File, bool) {
|
|
if v, found := fileCache.Get(file_uuid); found {
|
|
return v.(*dao.File), true
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func SetFileCache(file_uuid string, data *dao.File) {
|
|
fileCache.Set(file_uuid, data, cache.DefaultExpiration)
|
|
}
|