replace will add or replace an entry in the cache. If a parent is specified it will be added to that if not already there. If the parent does not exist, it will be added.
(path, parent string, e dataUsageEntry)
| 516 | // If a parent is specified it will be added to that if not already there. |
| 517 | // If the parent does not exist, it will be added. |
| 518 | func (d *dataUsageCache) replace(path, parent string, e dataUsageEntry) { |
| 519 | hash := hashPath(path) |
| 520 | if d.Cache == nil { |
| 521 | d.Cache = make(map[string]dataUsageEntry, 100) |
| 522 | } |
| 523 | d.Cache[hash.Key()] = e |
| 524 | if parent != "" { |
| 525 | phash := hashPath(parent) |
| 526 | p := d.Cache[phash.Key()] |
| 527 | p.addChild(hash) |
| 528 | d.Cache[phash.Key()] = p |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | // replaceHashed add or replaces an entry to the cache based on its hash. |
| 533 | // If a parent is specified it will be added to that if not already there. |