Documentation
¶
Overview ¶
Package filecache provides an LRU cache of opened files. If the same files are frequently opened and closed this is useful for reducing the number of syscalls for opening and closing the files.
Index ¶
- type FileCache
- func (c *FileCache) Cap() int
- func (c *FileCache) Clear()
- func (c *FileCache) Close(file *os.File) error
- func (c *FileCache) Len() int
- func (c *FileCache) Open(name string) (*os.File, error)
- func (c *FileCache) Remove(name string)
- func (c *FileCache) SetCacheSize(capacity int)
- func (c *FileCache) SetOnEvicted(f func(*os.File, int))
- func (c *FileCache) Stats() (int, int, int, int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
FileCache maintains a LRU cache of opened files. Its methods are safe to call concurrently.
func New ¶
New creates a new FileCache that can hold up to specified capacity of open files. If capacity is 0, then there is no limit. Files are opened read-only. If other open flags and permissions are needed, use NewOpenFile.
func NewOpenFile ¶
NewOpenFile created a new FileCache that opens files using the specified arguments to os.OpenFile.
func (*FileCache) Clear ¶
func (c *FileCache) Clear()
Clear removes all files in the FileCache and closes those that have a zero reference count.
func (*FileCache) Close ¶
Close decrements the reference count on the file. If the file has been removed from the cache and the reference count is zero, then the file is closed.
func (*FileCache) Open ¶
Open returns the already opened file, or opens the named file and returns that. The file is subsequently retrievable without opening it again, unless it has been removed from the FileCache.
All returned os.File instances are shared, so opeartions on these files must use methods that do not depend on the current file position.
Every call to Open must be accompanied by a call to Close. Otherwise, reference counts will not be adjusted correctly and file handles will leak.
func (*FileCache) Remove ¶
Remove removes the named file from the cache and closes it if it has a zero reference count.
func (*FileCache) SetCacheSize ¶
SetCacheSize sets the capacity of the FileCache. If the change reduces the capacity to fewer items than are currently in the cache, then the oldest items are removed until the number of items in the cache is equal to the new capacity.
func (*FileCache) SetOnEvicted ¶
SetOnEvicted specifies a function to call when a file is removed from cache.