/
cache.go
51 lines (42 loc) · 1.03 KB
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package blog
import (
logs "github.com/PacodiazDG/Backend-blog/components/logs"
"github.com/PacodiazDG/Backend-blog/extensions/redisbackend"
)
type Top50 struct {
Top []StoryStruct
}
var Blogs = InitControllerPost()
// Stores the feed in a variable allowing for faster access
var FastFeed []FeedStrcture
// Stores the last 50 most viewed stories allowing for quicker access
var StoryCacheVar *[]StoryStruct
// gets if the token is blacklisted from some database
func TokenBlackList(token, idtoken string) bool {
return redisbackend.CheckBan(token, idtoken)
}
// Update the top 50 most viewed stories
func SetLastStories() {
Blogs.SetCollection("Post")
info, err := Blogs.SetTop()
if err != nil {
logs.WriteLogs(err, logs.HardError)
panic(err)
}
StoryCacheVar = &info
}
// Update the fed
func SetTopFeed() {
Blogs.SetCollection("Post")
info, err := Blogs.FeedFast()
if err != nil {
logs.WriteLogs(err, logs.HardError)
return
}
FastFeed = info
}
// Updates stories and fed
func ReflexCache() {
SetTopFeed()
SetLastStories()
}