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