-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcache.go
39 lines (32 loc) · 785 Bytes
/
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
package pokeapi
import "time"
var CacheSettings = Settings{
CustomExpire: 0,
UseCache: true,
}
var defaultCacheSettings = defaultSettings{
MaxExpire: 10 * time.Minute,
MinExpire: 5 * time.Minute,
}
// defaultSettings are settings not meant to be changed.
type defaultSettings struct {
MaxExpire time.Duration
MinExpire time.Duration
}
// CacheSettings are user settings for cache expiration.
type Settings struct {
CustomExpire time.Duration
UseCache bool
}
// ClearCache clears all cached data.
func ClearCache() {
c.Flush()
}
// setCache adds new item to local cache.
func setCache(endpoint string, body []byte) {
if CacheSettings.CustomExpire != 0 {
c.Set(endpoint, body, CacheSettings.CustomExpire * time.Minute)
} else {
c.SetDefault(endpoint, body)
}
}