enhance(cache):为常用的缓存加入生命期设置。
This commit is contained in:
parent
c9f8235339
commit
b162844159
3
cache/entity.go
vendored
3
cache/entity.go
vendored
|
@ -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
3
cache/search.go
vendored
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user