Documentation
¶
Overview ¶
Package cachefs provides a caching and related wrappers for ReadFileFS implementations.
Index ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachingReadFileFS ¶
type CachingReadFileFS struct {
// contains filtered or unexported fields
}
CachingReadFileFS implements a caching layer over a ReadFileFS that is suitable for a small numbers of small files that can be readily kept in memory.
func NewCachingReadFileFS ¶
func NewCachingReadFileFS(fs file.ReadFileFS, opts ...Option) *CachingReadFileFS
NewCachingReadFileFS creates a new CachingReadFileFS with the specified TTL and cleanup interval. It starts a background goroutine to periodically clear out expired cache entries. Call Stop to stop the background goroutine.
func (*CachingReadFileFS) Forget ¶
func (c *CachingReadFileFS) Forget(name string)
Forget removes the named file from the cache.
func (*CachingReadFileFS) ReadFile ¶
func (c *CachingReadFileFS) ReadFile(name string) ([]byte, error)
ReadFile reads the named file, utilizing the cache if the entry is fresh.
func (*CachingReadFileFS) ReadFileCtx ¶
ReadFileCtx reads the named file using the provided context, utilizing the cache if fresh.
type Option ¶
type Option func(*options)
func WithCleanupInterval ¶
WithCleanupInterval specifies the interval for periodic background cleanup of expired entries. The default is DefaultCleanupInterval. A value of 0 disables periodic cleanup, with expired entries being overwritten on access.
func WithSingleFlight ¶
WithSingleFlight enables single-flight behavior for concurrent calls to ReadFileCtx with the same name. The default is false.
type SingleFlightReadFileFS ¶
type SingleFlightReadFileFS struct {
// contains filtered or unexported fields
}
SingleFlightReadFileFS is a wrapper around a ReadFileFS that provides single-flight behavior for concurrent calls to ReadFileCtx and ReadFile with the same name. This can be used in conjunction with CachingReadFileFS to prevent thundering herd issues on cache misses.
func NewSingleFlightReadFileFS ¶
func NewSingleFlightReadFileFS(fs file.ReadFileFS) *SingleFlightReadFileFS
func (*SingleFlightReadFileFS) ReadFile ¶
func (s *SingleFlightReadFileFS) ReadFile(name string) ([]byte, error)