GetCache tries to load saved templates otherwise it constructs new empty shards
(cacheFile string)
| 58 | // GetCache tries to load saved templates |
| 59 | // otherwise it constructs new empty shards |
| 60 | func GetCache(cacheFile string) MemCache { |
| 61 | var ( |
| 62 | mem memCacheDisk |
| 63 | err error |
| 64 | ) |
| 65 | |
| 66 | b, err := ioutil.ReadFile(cacheFile) |
| 67 | if err == nil { |
| 68 | err = json.Unmarshal(b, &mem) |
| 69 | if err == nil && mem.ShardNo == shardNo { |
| 70 | return mem.Cache |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | m := make(MemCache, shardNo) |
| 75 | for i := 0; i < shardNo; i++ { |
| 76 | m[i] = &TemplatesShard{Templates: make(map[uint32]Data)} |
| 77 | } |
| 78 | |
| 79 | return m |
| 80 | } |
| 81 | |
| 82 | func (m MemCache) getShard(id uint16, addr net.IP) (*TemplatesShard, uint32) { |
| 83 | b := make([]byte, 2) |
no outgoing calls