mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
931 B
41 lines
931 B
package dao
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"github.com/allegro/bigcache/v3"
|
|
"github.com/rocboss/paopao-ce/internal/core"
|
|
"github.com/rocboss/paopao-ce/internal/model"
|
|
)
|
|
|
|
var (
|
|
_ core.CacheIndexService = (*simpleCacheIndexServant)(nil)
|
|
_ core.CacheIndexService = (*bigCacheIndexServant)(nil)
|
|
)
|
|
|
|
type postsEntry struct {
|
|
key string
|
|
posts []*model.PostFormated
|
|
}
|
|
|
|
type indexPostsFunc func(int64, int, int) ([]*model.PostFormated, error)
|
|
|
|
type bigCacheIndexServant struct {
|
|
getIndexPosts indexPostsFunc
|
|
indexActionCh chan core.IndexActionT
|
|
cachePostsCh chan *postsEntry
|
|
cache *bigcache.BigCache
|
|
lastCacheResetTime time.Time
|
|
}
|
|
|
|
type simpleCacheIndexServant struct {
|
|
getIndexPosts indexPostsFunc
|
|
indexActionCh chan core.IndexActionT
|
|
indexPosts []*model.PostFormated
|
|
atomicIndex atomic.Value
|
|
maxIndexSize int
|
|
checkTick *time.Ticker
|
|
expireIndexTick *time.Ticker
|
|
}
|