Documentation
¶
Index ¶
- Constants
- Variables
- type CacheInfo
- type CacheItemPair
- type CacheItemPairList
- type FileCache
- func (cache *FileCache) Active() bool
- func (cache *FileCache) Cache(name string, content []byte)
- func (cache *FileCache) CacheNow(name string) (err error)
- func (cache *FileCache) FileSize() (totalSize int64)
- func (cache *FileCache) GetItem(name string) (content []byte, ok bool)
- func (cache *FileCache) GetItemString(name string) (content string, ok bool)
- func (cache *FileCache) InCache(name string) bool
- func (cache *FileCache) MostAccessed(count int64) []*cacheItem
- func (cache *FileCache) ReadFile(name string) (content []byte, err error)
- func (cache *FileCache) ReadFileString(name string) (content string, err error)
- func (cache *FileCache) Remove(name string) (ok bool, err error)
- func (cache *FileCache) Size() int
- func (cache *FileCache) Start() error
- func (cache *FileCache) Stop()
- func (cache *FileCache) StoredFiles() (fileList []string)
- func (cache *FileCache) WriteFile(w io.Writer, name string) (err error)
- func (cache *FileCache) WriteItem(w io.Writer, name string) (err error)
Constants ¶
const ( Kilobyte = 1024 Megabyte = 1024 * 1024 Gigabyte = 1024 * 1024 * 1024 )
File size constants for use with FileCache.MaxSize. For example, cache.MaxSize = 64 * Megabyte
Variables ¶
var ( InvalidCacheItem = errors.New("invalid cache item") ItemIsDirectory = errors.New("can't cache a directory") ItemNotInCache = errors.New("item not in cache") ItemTooLarge = errors.New("item too large for cache") WriteIncomplete = errors.New("incomplete write of cache item") )
var ( SquelchItemNotInCache bool = true DefaultExpireItem int = 300 // 5 minutes // Max size for each item DefaultMaxSize int64 = 16 * Megabyte // Max amount of items DefaultMaxItems int = 32 // Check interval by seconds DefaultEvery int = 60 // 1 minute // Mumber of items to buffer adding to the file cache. NewCachePipeSize int = runtime.NumCPU() * 8 )
Functions ¶
This section is empty.
Types ¶
type CacheItemPair ¶ added in v1.0.4
CacheItemPair maps key to access counter
type CacheItemPairList ¶ added in v1.0.4
type CacheItemPairList []CacheItemPair
func (CacheItemPairList) Len ¶ added in v1.0.4
func (p CacheItemPairList) Len() int
func (CacheItemPairList) Less ¶ added in v1.0.4
func (p CacheItemPairList) Less(i, j int) bool
func (CacheItemPairList) Swap ¶ added in v1.0.4
func (p CacheItemPairList) Swap(i, j int)
type FileCache ¶
type FileCache struct { MaxItems int // Maximum number of files to cache MaxSize int64 // Maximum file size to store ExpireItem int // Seconds a file should be cached for Every int // Run an expiration check Every seconds // contains filtered or unexported fields }
FileCache represents a cache in memory. An ExpireItem value of 0 means that items should not be expired based on time in memory.
func NewDefaultCache ¶
func NewDefaultCache() *FileCache
NewDefaultCache returns a new FileCache with sane defaults.
func (*FileCache) Cache ¶
Cache will store the file named by 'name' to the cache. This function doesn't return anything as it passes the file onto the incoming pipe; the file will be cached asynchronously. Errors will not be returned.
func (*FileCache) GetItem ¶
GetItem returns the content of the item and a bool if name is present. GetItem should be used when you are certain an object is in the cache, or if you want to use the cache only.
func (*FileCache) GetItemString ¶
GetItemString is the same as GetItem, except returning a string.
func (*FileCache) MostAccessed ¶ added in v1.0.4
MostAccessed returns the most accessed items in this cache cache
func (*FileCache) ReadFile ¶
ReadFile retrieves the file named by 'name'. If the file is not in the cache, load the file and cache the file in the background. If the file was not in the cache and the read was successful, the error ItemNotInCache is returned to indicate that the item was pulled from the filesystem and not the cache, unless the SquelchItemNotInCache global option is set; in that case, returns no error.
func (*FileCache) ReadFileString ¶
ReadFileString is the same as ReadFile, except returning a string.
func (*FileCache) Remove ¶
RemoveItem immediately removes the item from the cache if it is present. It returns a boolean indicating whether anything was removed, and an error if an error has occurred.
func (*FileCache) Start ¶
Start activates the file cache; it will start up the background caching and automatic cache expiration goroutines and initialise the internal data structures.
func (*FileCache) Stop ¶
func (cache *FileCache) Stop()
Stop turns off the file cache. This closes the concurrent caching mechanism, destroys the cache, and the background scanner that it should stop. If there are any items or cache operations ongoing while Stop() is called, it is undefined how they will behave.
func (*FileCache) StoredFiles ¶
StoredFiles returns the list of files stored in the cache.