Documentation ¶
Overview ¶
Package cache provides methods for creating and using a cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteCache ¶
DeleteCache removes all traces of a cache located at cachepath.
Types ¶
type Cache ¶
type Cache interface { // Adds a value to the cache. Add(key Key, value interface{}) interface{} // Returns key's value from the cache. Get(key Key) (interface{}, bool) // Checks if a key exists in cache. Contains(key Key) bool // Removes a key from the cache. Remove(key Key) interface{} // Returns the number of items in the cache. Len() int // Clears all cache entries. Clear() }
Cache is the interface for cache.
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
FileCache represents a cache of files stored somewhere on the disk. It is possible to use the cache concurrently from any number of processes or threads.
func GetFileCache ¶
GetFileCache will attempt to load an existing cache if one exists. If one does not it will create a cache with the given size.
func LoadFileCache ¶
LoadFileCache loads a persistent cache from the file system.
func NewFileCache ¶
NewFileCache creates a new persistent cache on the file system.
func (*FileCache) Add ¶
Add adds an entry into the cache so that it might later be accessed via Get.
func (*FileCache) Get ¶
func (fc *FileCache) Get(key FileKey) (*LinkedFile, error)
Get returns a LinkedFile to an entry for the given key if one exists.
func (*FileCache) Update ¶
Update starts a goroutine to periodically check on the status of the cache. The cache can be operated without using Update but if Update is not called the cache's estimate of the cache size will diverge from reality. If many actors are present this can cause the cache size to be very different from this actor's estimate.
type FileKey ¶
type FileKey interface { // Hash should return a valid unique file name to be used as the key. Hash() string }
FileKey is the interface of keys that can be used to index cached files.
type LRUCache ¶
type LRUCache struct { // Size is the maximum number of entries before an item is evicted. // Zero means no limit on the number of entries. Size uint // contains filtered or unexported fields }
LRUCache is a simple LRU cache.
func (*LRUCache) Add ¶
Add adds a value to the cache and updates the "recently used"-ness of the key.
func (*LRUCache) Contains ¶
Contains checks if a key exists in cache without updating the recent-ness.
type LinkedFile ¶
type LinkedFile string
LinkedFile removes the file it names on closing. This is used to link files into a temporary directory while they're being used so that collection of old files doesn't delete a file that's in use. This effectivelly uses the inode count as a reference counter for the file.