Documentation ¶
Overview ¶
Package cache implements the data store behind Airlift server.
Index ¶
- Constants
- type Cache
- func (c *Cache) CutToCount(n int) (m int, err error)
- func (c *Cache) CutToSize(n int64) ([]string, error)
- func (c *Cache) Get(id string) string
- func (c *Cache) Len() int
- func (c *Cache) MaybeCutToSize(n int64) (m int)
- func (c *Cache) MaybeRemoveOlderThan(t time.Time) int
- func (c *Cache) Put(content io.Reader, filename string, conf Config) (string, error)
- func (c *Cache) Remove(id string) error
- func (c *Cache) RemoveAll() error
- func (c *Cache) RemoveNewest() (string, error)
- func (c *Cache) RemoveOlderThan(t time.Time) ([]string, error)
- func (c *Cache) SetDir(dir string)
- func (c *Cache) Size() int64
- func (c *Cache) SortedIDs() []string
- func (c *Cache) Stat(id string) os.FileInfo
- func (c *Cache) WatchAges(conf Config)
- type Config
Constants ¶
const SHASize = 64
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { // OnRemove is an arbitrary callback that is called whenever a file is // successfully removed. OnRemove func(id string) *sync.RWMutex // contains filtered or unexported fields }
Cache is an extremely naïve, map-based, fully in-memory key-value store configured as a file cache. Only file locations are stored in memory. Persistence is achieved through the file system. It is concurrent-access safe through locking.
func (*Cache) CutToCount ¶
CutCoCount removes the oldest file until the number of files in the cache is less than or equal to n.
func (*Cache) CutToSize ¶
CutToSize removes the oldest file in the cache until the total size is at most n bytes, returning the IDs of the deleted files. Nothing will happen if n == 0. To remove all files, use RemoveAll.
func (*Cache) MaybeCutToSize ¶
MaybeCutToSize returns how many files would be pruned if CutToSize would have been called.
func (*Cache) MaybeRemoveOlderThan ¶
MaybeRemoveOlderThan returns the number of files that would be deleted if RemoveOlderThan were to be called.
func (*Cache) RemoveNewest ¶
RemoveNewest removes the most recently modified item in the cache. It returns the ID of the file that was removed and an error if one was encountered.
func (*Cache) RemoveOlderThan ¶
RemoveOlderThan removes all files in the cache that were modified before t, returning the IDs of the deleted files. If an error is encountered while deleting a file, it will not advance any further.
func (*Cache) SortedIDs ¶
SortedIDs returns a slice of every cached file's ID, sorted descending by modification time.