Documentation
¶
Index ¶
- Constants
- type MemoryCache
- func (mc *MemoryCache) Delete(path string) bool
- func (mc *MemoryCache) Read(path string, buff []byte, ofst int64) (n int, err error)
- func (mc *MemoryCache) StartMaintenance()
- func (mc *MemoryCache) Stats() *cache.Stats
- func (mc *MemoryCache) StopMaintenance()
- func (mc *MemoryCache) Write(path string, buff []byte, ofst int64) (int, error)
- type Option
Constants ¶
const ( // DefaultCacheCapacity is the maximum size of the cache in bytes if not provided // at cache initialization. Equivalent to 1GiB DefaultCapacity = 1 << 30 // MinCapacity is the minimum size of the cache. Equivalent to 256MiB MinCapacity = 256 << 20 // MaxCapacity is the maximum size of the cache. Equivalent to 5GiB MaxCapacity = 5 << 30 // DefaultMaxAge is the maximum age of cache files, if not provided // at cache initialization. 0 means no expiration. Equivalent to 12 hours. DefaultMaxAge = 12 * time.Hour // DefaultMaxFileCount is the maximum number of files in the cache if not provided // at cache initialization. 0 means unbounded. DefaultMaxFileCount = 1000 // DefaultMaintenanceInterval is the interval at which cache maintenance tasks are performed, // if not provided at cache initialization. DefaultMaintenanceInterval = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemoryCache ¶
type MemoryCache struct {
Capacity int64
MaxFileCount int64
MaxAge time.Duration
MaintenanceInterval time.Duration
// contains filtered or unexported fields
}
MemoryCache implements a simple in memory LRU cache for file data with an interface that roughly matches the FUSE Read/Write methods.
TODO:
- allow concurrent reads/writes to different files in the cache by moving lock coordination out of the caller and lock by path within the cache with a RWMutex map. This will require maintaining a reservation of bytes so that concurrent goroutines can't exhaust memory that a different goroutine evicted for its Write operation.
func NewMemoryCache ¶
func NewMemoryCache(opts ...Option) (*MemoryCache, error)
func (*MemoryCache) Delete ¶
func (mc *MemoryCache) Delete(path string) bool
Delete removes the cached file at the given path from the cache.
func (*MemoryCache) Read ¶
Read reads data from the cached file at the given path into buff starting at the provided offset.
func (*MemoryCache) StartMaintenance ¶
func (mc *MemoryCache) StartMaintenance()
StartMaintenance starts the maintenance goroutine if it is not already running.
func (*MemoryCache) Stats ¶
func (mc *MemoryCache) Stats() *cache.Stats
Stats returns the current cache statistics.
func (*MemoryCache) StopMaintenance ¶
func (mc *MemoryCache) StopMaintenance()
StopMaintenance stops the maintenance goroutine if it is running.
type Option ¶
type Option func(*MemoryCache)
Option configures a MemoryCache.
func WithCapacityBytes ¶
WithCapacityBytes sets the maximum total size (in bytes) for the cache.
func WithLogger ¶
WithLogger sets the logger for the cache.
func WithMaintenanceInterval ¶
WithMaintenanceInterval sets the interval for cache maintenance operations.
func WithMaxAge ¶
WithMaxAge sets the maximum age for cache files.
func WithMaxFileCount ¶
WithMaxFileCount sets the maximum number of files for the cache.