filecache

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2020 License: AGPL-3.0 Imports: 4 Imported by: 0

README

A simple LRU FileCache with file freshness monitor.

FileCache accepts a max size and age, and will remove items if they become too old or at end of the LRU list.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedFile

type CachedFile struct {
	upmutex.UpgradeableMutex
	// contains filtered or unexported fields
}

CachedFile provides a structure for managing a cached file including freshness, last refresh time etc

func NewFile

func NewFile(path string, onDisk bool, content interface{}) *CachedFile

NewFile returns a new File based on supplied FileContents

func (*CachedFile) Content

func (f *CachedFile) Content() interface{}

Content returns the underlying provided interface

func (*CachedFile) IsFresh

func (f *CachedFile) IsFresh() bool

IsFresh returns whether the provided file is fresh

func (*CachedFile) Path

func (f *CachedFile) Path() string

Path returns the file absolute path

func (*CachedFile) UpdateLastRefresh

func (f *CachedFile) UpdateLastRefresh()

UpdateLastRefresh updates the last refresh time to now and sets file as fresh

type FileCache

type FileCache struct {
	upmutex.UpgradeableMutex
	// contains filtered or unexported fields
}

FileCache is an LRU cache with filesystem monitoring. UpgradeableMutex is built-in to the FileCache and CachedFile objects it manages for multi-threading

func NewFileCache

func NewFileCache(size int, maxAge time.Duration) *FileCache

NewFileCache returns a new FileCache object of size, and max file age

func (*FileCache) Get

func (fc *FileCache) Get(path string) (*CachedFile, bool)

Get looks for and tries to return a CachedFile object from the FileCache. NOTE: THIS IS NOT THREADSAFE, PLEASE USE FileCache.RLock()

func (*FileCache) Iterate

func (fc *FileCache) Iterate(iterFunc func(*CachedFile))

Iterate performs an unordered iteration through the FileCache, performing provided function on each key,value pair. NOTE: THIS IS NOT THREAD SAFE, PLEASE USE FileCache.RLock()

func (*FileCache) IterateOrdered

func (fc *FileCache) IterateOrdered(iterFunc func(*CachedFile))

IterateOrdered performs an ordered iteration through the FileCache, performing provided function on each key,value pair. NOTE: THIS IS NOT THREADSAFE OR WRITE SAFE, PLEASE DO NOT MODIFY THE FileCache MID-ITERATION, AND ENSURE TO USE FileCache.RLock()

func (*FileCache) Put

func (fc *FileCache) Put(f *CachedFile)

Put places a CachedFile object in the FileCache. NOTE: THIS IS NOT THREADSAFE, PLEASE USE FileCache.Lock()

func (*FileCache) Remove

func (fc *FileCache) Remove(path string)

Remove tries to remove a CachedFile with Path from the FileCache. NOTE: THIS IS NOT THREADSAFE, PLEASE USE FileCache.Lock()

func (*FileCache) StartMonitor

func (fc *FileCache) StartMonitor(d time.Duration)

StartMonitor starts the FileCache freshness monitor in its own goroutine

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL