Exists checks if the file exists in the cache.
(name string, offset int64)
| 30 | |
| 31 | // Exists checks if the file exists in the cache. |
| 32 | func (c *fileCache) Exists(name string, offset int64) bool { |
| 33 | key := c.getKey(name, offset) |
| 34 | val, found := c.fileCache.Get(key) |
| 35 | if found { |
| 36 | cacheItem := val.(*item) |
| 37 | cacheItem.lock.Lock() |
| 38 | defer cacheItem.lock.Unlock() |
| 39 | |
| 40 | if info, err := cacheItem.file.Stat(); err != nil { |
| 41 | return false |
| 42 | } else { |
| 43 | return info.Size() > 0 |
| 44 | } |
| 45 | } |
| 46 | return false |
| 47 | } |
| 48 | |
| 49 | // GetOrCreate gets the cached value if available, otherwise fetches it. |
| 50 | func (c *fileCache) GetOrCreate(name string, alignedOffset int64, count int, fetch func() ([]byte, error)) ([]byte, error) { |