enhance(cache):为常用的缓存加入生命期设置。

This commit is contained in:
徐涛 2022-09-02 19:50:40 +08:00
parent c9f8235339
commit b162844159
2 changed files with 4 additions and 2 deletions

3
cache/entity.go vendored
View File

@ -3,6 +3,7 @@ package cache
import (
"fmt"
"strings"
"time"
)
func assembleEntityKey(entityName, id string) string {
@ -19,7 +20,7 @@ func assembleEntityKey(entityName, id string) string {
// 缓存模型名称明确的使用ID进行检索的实体内容。
func CacheEntity[T any](instance T, relationNames []string, entityName, id string) error {
entityKey := assembleEntityKey(entityName, id)
err := Cache(entityKey, &instance, -1)
err := Cache(entityKey, &instance, 5*time.Minute)
for _, relationName := range relationNames {
CacheRelation(relationName, STORE_TYPE_KEY, entityKey)
}

3
cache/search.go vendored
View File

@ -3,6 +3,7 @@ package cache
import (
"fmt"
"strings"
"time"
)
func assembleSearchKey(entityName string, additional ...string) string {
@ -20,7 +21,7 @@ func assembleSearchKey(entityName string, additional ...string) string {
// 缓存模型名称明确的使用或者包含非ID检索条件的实体内容。
func CacheSearch[T any](instance T, relationNames []string, entityName string, conditions ...string) error {
searchKey := assembleSearchKey(entityName, conditions...)
err := Cache(searchKey, &instance, -1)
err := Cache(searchKey, &instance, 5*time.Minute)
for _, relationName := range relationNames {
CacheRelation(relationName, STORE_TYPE_KEY, searchKey)
}