完善
This commit is contained in:
parent
1ac3b77941
commit
3636c3952a
|
@ -14,12 +14,12 @@ import (
|
||||||
var PostsCache sync.Map
|
var PostsCache sync.Map
|
||||||
var PostContextCache sync.Map
|
var PostContextCache sync.Map
|
||||||
|
|
||||||
var archivesCaches *Arch[models.PostArchive]
|
var archivesCaches *Arch
|
||||||
var categoryCaches *cache.SliceCache[models.WpTermsMy]
|
var categoryCaches *cache.SliceCache[models.WpTermsMy]
|
||||||
var recentPostsCaches *cache.SliceCache[models.WpPosts]
|
var recentPostsCaches *cache.SliceCache[models.WpPosts]
|
||||||
|
|
||||||
func InitCache() {
|
func InitCache() {
|
||||||
archivesCaches = &Arch[models.PostArchive]{
|
archivesCaches = &Arch{
|
||||||
mutex: &sync.Mutex{},
|
mutex: &sync.Mutex{},
|
||||||
setCacheFunc: archives,
|
setCacheFunc: archives,
|
||||||
}
|
}
|
||||||
|
@ -27,15 +27,14 @@ func InitCache() {
|
||||||
recentPostsCaches = cache.NewSliceCache[models.WpPosts](recentPosts, vars.Conf.RecentPostCacheTime)
|
recentPostsCaches = cache.NewSliceCache[models.WpPosts](recentPosts, vars.Conf.RecentPostCacheTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Arch[T any] struct {
|
type Arch struct {
|
||||||
cache.SliceCache[T]
|
data []models.PostArchive
|
||||||
data []T
|
|
||||||
mutex *sync.Mutex
|
mutex *sync.Mutex
|
||||||
setCacheFunc func() ([]T, error)
|
setCacheFunc func() ([]models.PostArchive, error)
|
||||||
month time.Month
|
month time.Month
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Arch[T]) GetCache() []T {
|
func (c *Arch) GetCache() []models.PostArchive {
|
||||||
l := len(c.data)
|
l := len(c.data)
|
||||||
m := time.Now().Month()
|
m := time.Now().Month()
|
||||||
if l > 0 && c.month != m || l < 1 {
|
if l > 0 && c.month != m || l < 1 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user