Documentation ¶
Overview ¶
Package parsecache provides a structure which caches parsed files and directory entries on top of a filesystem.
Index ¶
- func JsonParser[T any](f io.Reader) (T, error)
- type CachedDir
- type CachedFile
- type ConcurrentCachedDir
- type ConcurrentCachedFile
- type ConcurrentFsCache
- func (cache *ConcurrentFsCache[T]) Clear()
- func (cache *ConcurrentFsCache[T]) ClearDirs()
- func (cache *ConcurrentFsCache[T]) ClearFiles()
- func (cache *ConcurrentFsCache[T]) GetDir(dir string) ([]fs.DirEntry, error)
- func (cache *ConcurrentFsCache[T]) GetDirEntry(path string) (entry *ConcurrentCachedDir, ok bool)
- func (cache *ConcurrentFsCache[T]) GetDirWithMaxAge(dir string, maxAge time.Duration) ([]fs.DirEntry, error)
- func (cache *ConcurrentFsCache[T]) GetFile(file string) (T, error)
- func (cache *ConcurrentFsCache[T]) GetFileEntry(path string) (entry *ConcurrentCachedFile[T], ok bool)
- func (cache *ConcurrentFsCache[T]) GetFileWithMaxAge(file string, maxAge time.Duration) (T, error)
- func (cache *ConcurrentFsCache[T]) SetMaxAge(maxAge time.Duration)
- type FsCache
- func (cache *FsCache[T]) Clear()
- func (cache *FsCache[T]) ClearDirs()
- func (cache *FsCache[T]) ClearFiles()
- func (cache *FsCache[T]) GetDir(dir string) ([]fs.DirEntry, error)
- func (cache *FsCache[T]) GetDirEntry(path string) (entry *CachedDir, ok bool)
- func (cache *FsCache[T]) GetDirWithMaxAge(dir string, maxAge time.Duration) ([]fs.DirEntry, error)
- func (cache *FsCache[T]) GetFile(file string) (T, error)
- func (cache *FsCache[T]) GetFileEntry(path string) (entry *CachedFile[T], ok bool)
- func (cache *FsCache[T]) GetFileWithMaxAge(file string, maxAge time.Duration) (T, error)
- type Parser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CachedDir ¶
type CachedDir struct {
// contains filtered or unexported fields
}
CachedDir stores a cache entry for a directory.
type CachedFile ¶
type CachedFile[T any] struct { // contains filtered or unexported fields }
CachedFile stores a cache entry for a file.
func (*CachedFile[T]) Cached ¶
func (f *CachedFile[T]) Cached() (T, time.Time, bool)
Cached returns the cached content, the time it was cached, and a boolean, which is true only if the cache entry has been loaded.
func (*CachedFile[T]) Get ¶
func (f *CachedFile[T]) Get(open func() (fs.File, error), parser Parser[T], maxAge time.Duration) (T, error)
Get the parsed file content, the results may be cached upto the specified `maxAge`.
`open` should open the underlying file is required, this will be once or not at all.
type ConcurrentCachedDir ¶
type ConcurrentCachedDir struct {
// contains filtered or unexported fields
}
ConcurrentCachedDir is a concurrency-safe wrapper around a `CachedDir`.
func (*ConcurrentCachedDir) Cached ¶
Cached returns the cached entries, the time it was cached, and a boolean, which is true only if the cache entry has been loaded.
func (*ConcurrentCachedDir) Get ¶
func (f *ConcurrentCachedDir) Get(open func() (fs.File, error), maxAge time.Duration) ([]fs.DirEntry, error)
Get the directory entries, the results may be cached upto the specified `maxAge`.
`open` should open the underlying file is required, this will be once or not at all.
type ConcurrentCachedFile ¶
type ConcurrentCachedFile[T any] struct { // contains filtered or unexported fields }
ConcurrentCachedFile is a concurrency-safe wrapper around a `CachedFile`.
func (*ConcurrentCachedFile[T]) Cached ¶
func (f *ConcurrentCachedFile[T]) Cached() (T, time.Time, bool)
Cached returns the cached content, the time it was cached, and a boolean, which is true only if the cache entry has been loaded.
func (*ConcurrentCachedFile[T]) Get ¶
func (f *ConcurrentCachedFile[T]) Get(open func() (fs.File, error), parser Parser[T], maxAge time.Duration) (T, error)
Get the parsed file content, the results may be cached upto the specified `maxAge`.
`open` should open the underlying file is required, this will be once or not at all.
type ConcurrentFsCache ¶
type ConcurrentFsCache[T any] struct { // contains filtered or unexported fields }
FsCache is a concurrency safe cache on top of a generic filesystem.
It can cache directory listings and parsed file content.
func NewConcurrentFsCache ¶
func NewConcurrentFsCache[T any](fs fs.FS, parser Parser[T], maxAge time.Duration) *ConcurrentFsCache[T]
NewConcurrentFsCache returns a new cache on top of the `fs` filesystem, safe for concurrent access, using `parser` to parse the content of files and sets the maximum age of cache entries to `maxAge`.
`fs` must be safe for concurrent use.
func (*ConcurrentFsCache[T]) ClearDirs ¶
func (cache *ConcurrentFsCache[T]) ClearDirs()
ClearDirs from the cache.
func (*ConcurrentFsCache[T]) ClearFiles ¶
func (cache *ConcurrentFsCache[T]) ClearFiles()
ClearFiles from the cache.
func (*ConcurrentFsCache[T]) GetDir ¶
func (cache *ConcurrentFsCache[T]) GetDir(dir string) ([]fs.DirEntry, error)
GetDir gets the entries of a directory, which may be cached.
func (*ConcurrentFsCache[T]) GetDirEntry ¶
func (cache *ConcurrentFsCache[T]) GetDirEntry(path string) (entry *ConcurrentCachedDir, ok bool)
GetDirEntry gets the `ConcurrentCachedDir` for the path if one exists.
func (*ConcurrentFsCache[T]) GetDirWithMaxAge ¶
func (cache *ConcurrentFsCache[T]) GetDirWithMaxAge(dir string, maxAge time.Duration) ([]fs.DirEntry, error)
GetDirWithMaxAge gets the entries of a directory, with the specified maximum age.
func (*ConcurrentFsCache[T]) GetFile ¶
func (cache *ConcurrentFsCache[T]) GetFile(file string) (T, error)
GetFile returns the parsed content of a file, which may be cached.
func (*ConcurrentFsCache[T]) GetFileEntry ¶
func (cache *ConcurrentFsCache[T]) GetFileEntry(path string) (entry *ConcurrentCachedFile[T], ok bool)
GetFileEntry gets the `CachedFile` for the path if one exists.
func (*ConcurrentFsCache[T]) GetFileWithMaxAge ¶
func (cache *ConcurrentFsCache[T]) GetFileWithMaxAge(file string, maxAge time.Duration) (T, error)
GetFileWithMaxAge returns the parsed content of a file, which may be cached.
func (*ConcurrentFsCache[T]) SetMaxAge ¶
func (cache *ConcurrentFsCache[T]) SetMaxAge(maxAge time.Duration)
type FsCache ¶
type FsCache[T any] struct { // MaxAge is the maximum allowed age of a cache entry. MaxAge time.Duration // contains filtered or unexported fields }
FsCache is a cache on top of a generic filesystem. It's not safe for concurrent use, use `ConcurrentFsCache` for a thread-safe version.
It can cache directory listings and parsed file content.
func NewFsCache ¶
NewFsCache creates a new cache on top of the `fs` filesystem, using `parser` to parse the content of files and sets the maximum age of cache entries to `maxAge`.
func (*FsCache[T]) GetDirEntry ¶
GetDirEntry gets the `CachedDir` for the path if one exists.
func (*FsCache[T]) GetDirWithMaxAge ¶
GetDirWithMaxAge gets the entries of a directory, with the specified maximum age.
func (*FsCache[T]) GetFileEntry ¶
func (cache *FsCache[T]) GetFileEntry(path string) (entry *CachedFile[T], ok bool)
GetFileEntry gets the `CachedFile` for the path if one exists.