预热时判断允许的最大内容长度

This commit is contained in:
GoEdgeLab
2021-01-11 11:51:05 +08:00
parent 687a6a5c8f
commit 5edef48d3a
2 changed files with 10 additions and 2 deletions

View File

@@ -1 +0,0 @@
cache

View File

@@ -372,8 +372,17 @@ func (this *APIStream) handlePreheatCache(message *pb.NodeStreamMessage) error {
_ = resp.Body.Close()
}()
// 检查最大内容长度
maxSize := storage.Policy().MaxSizeBytes()
if maxSize > 0 && resp.ContentLength > maxSize {
locker.Lock()
errorMessages = append(errorMessages, "request failed: the content is too larger than policy setting")
locker.Unlock()
return
}
expiredAt := time.Now().Unix() + 8600
writer, err := storage.Open(key, expiredAt) // TODO 可以设置缓存过期事件
writer, err := storage.Open(key, expiredAt) // TODO 可以设置缓存过期时间
if err != nil {
locker.Lock()
errorMessages = append(errorMessages, "open cache writer failed: "+key+": "+err.Error())