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(cache_prefix+"database", h) }