lru: Index | Files | Directories

package lru

import ""

Package lru provides a tool to prune files from a cache based on LRU.

lru implements a cache structure that tracks the size and (modified*) time of a file.

* future versions of lru may use different time method to better approximate usage time rather than modification time.


Package Files

cache.go file.go heap.go populate.go prune.go

type Cache Uses

type Cache struct {
    // contains filtered or unexported fields

Cache provides tools to maintain an cache of file system objects, maintained on a least-recently-used basis. Internally, files are stored internally as a heap.

func DirectoryContents Uses

func DirectoryContents(path string, skipDir bool) (*Cache, error)

DirectoryContents takes a path and builds a cache object. If skipDir is true, this option does not include any directories, otherwise all directories are included in the cache. When including directories in the cache, lru includes the aggregate size of files in the directory.

func NewCache Uses

func NewCache() *Cache

NewCache returns an initalized but unpopulated cache. Use the DirectoryContents and TreeContents constructors to populate a cache.

func TreeContents Uses

func TreeContents(root string) (*Cache, error)

TreeContents adds all file system items, excluding directories, to a cache object.

func (*Cache) Add Uses

func (c *Cache) Add(f *FileObject) error

Add takes a defined FileObject and adds it to the cache, returning an error if the object already exists.

func (*Cache) AddFile Uses

func (c *Cache) AddFile(fn string) error

AddFile takes a fully qualified filename and adds it to the cache, returning an error if the file does not exist. AddStat returns an error if the stat is invalid, or the file already exists in the cache.

func (*Cache) AddStat Uses

func (c *Cache) AddStat(fn string, stat os.FileInfo) error

AddStat takes the full (absolute) path to a file and an os.FileInfo object and and constructs the FileObject and adds it to the cache. AddStat returns an error if the stat is invalid, or the file already exists in the chace.

func (*Cache) Contents Uses

func (c *Cache) Contents() <-chan string

Contents returns an iterator for

func (*Cache) Count Uses

func (c *Cache) Count() int

Count returns the total number of objects in the cache.

func (*Cache) Get Uses

func (c *Cache) Get(path string) (*FileObject, error)

Get returns an item from the cache by name. This does not impact the item's position in the cache.

func (*Cache) Pop Uses

func (c *Cache) Pop() (*FileObject, error)

Pop removes and returns the oldest object in the cache.

func (*Cache) Prune Uses

func (c *Cache) Prune(maxSize int, exclude []string, dryRun bool) error

Prune removes files (when dryRun is false), from the file system until the total size of the cache is less than the maxSize (in bytes.)

func (*Cache) Size Uses

func (c *Cache) Size() int

Size returns the total size of objects in the cache.

func (*Cache) Update Uses

func (c *Cache) Update(f *FileObject) error

Update updates an existing item in the cache, returning an error if it is not in the cache.

type FileObject Uses

type FileObject struct {
    Size int
    Time time.Time
    Path string
    // contains filtered or unexported fields

FileObject is a simple struct that tracks data

func NewFile Uses

func NewFile(fn string, info os.FileInfo) *FileObject

NewFile constructs a FileObject from its pathname and an os.FileInfo object. If the object is a directory, this method does not sum the total size of the directory.

func (*FileObject) Remove Uses

func (f *FileObject) Remove() error

Remove deletes the file object, recursively if necessary.

func (*FileObject) Update Uses

func (f *FileObject) Update() error

Update refreshs the objects data, and sums the total size of all objects in a directory if the object refers to a directory.


buildscriptsThe current vendoring solution supports both new and old style vendoring, via a trick: We commit all vendored code to the "vendor" directory, and then, if we're on a version/deployment of go that doesn't support new style vendoring, we symlink to "build/vendor/src" and add "build/vendor" to the gopath, which the render-gopath program generates inside of the makefile.
buildscripts/vendoringPackage vendoring provides a several variables used in vendoring buildscripts and function that reports (without any external dependencies) if the current environment requires legacy-style vendoring, or if its safe to use new-style vendoring.

Package lru imports 9 packages (graph) and is imported by 6 packages. Updated 2018-11-14. Refresh now. Tools for package owners.