blob: 4e8ece2fd6f1811f772ddf805007c2c0273c1d8a (
plain)
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 main
import (
"encoding/json"
"github.com/garyburd/redigo/redis"
"log"
)
const (
cache_prefix = "status_"
)
func CacheHosts(prefix string, h []Host) error {
c := pool.Get()
js, err := json.Marshal(h)
if err != nil {
log.Println("Serizaling to JSON failed.")
return err
}
c.Do("SET", prefix, js)
return nil
}
func GetCache(key string) (string, error) {
c := pool.Get()
return redis.String(c.Do("GET", key))
}
func DelCache(key string) error {
c := pool.Get()
_, err := c.Do("DEL", key)
return err
}
func FillCache() error {
h := []Host{}
Db.Find(&h)
return CacheHosts("database", h)
}
|