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.
46 lines
1.0 KiB
46 lines
1.0 KiB
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)
|
|
_ core.CacheIndexService = (*noneCacheIndexServant)(nil)
|
|
)
|
|
|
|
type postsEntry struct {
|
|
key string
|
|
posts []*model.PostFormated
|
|
}
|
|
|
|
type indexPostsFunc func(*model.User, 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
|
|
}
|
|
|
|
type noneCacheIndexServant struct {
|
|
getIndexPosts indexPostsFunc
|
|
}
|