()
| 28 | ) |
| 29 | |
| 30 | func (m *MapCache) Get() (sqlread.SummaryTree, error) { |
| 31 | cf, err := os.Open(m.getCacheFile()) |
| 32 | defer cf.Close() |
| 33 | if os.IsNotExist(err) { |
| 34 | return nil, ErrCacheMiss |
| 35 | } else if err != nil { |
| 36 | return nil, err |
| 37 | } |
| 38 | |
| 39 | d := json.NewDecoder(cf) |
| 40 | |
| 41 | v := cacheInfo{} |
| 42 | err = d.Decode(&v) |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | |
| 47 | if v.FileSize != m.getFileSize() { // @todo more validation |
| 48 | return nil, ErrCacheMiss |
| 49 | } |
| 50 | |
| 51 | if v.Version != CacheVersion { |
| 52 | return nil, ErrCacheMiss |
| 53 | } |
| 54 | |
| 55 | return v.Tree, nil |
| 56 | } |
| 57 | |
| 58 | func (m *MapCache) Store(s sqlread.SummaryTree) error { |
| 59 | cf, err := os.OpenFile(m.getCacheFile(), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) |
no test coverage detected