feat: add configurations for memory only, disk only, and memory & disk modes
All checks were successful
Release Tag / release (push) Successful in 14s
All checks were successful
Release Tag / release (push) Successful in 14s
This commit is contained in:
25
vfs/cache/cache.go
vendored
25
vfs/cache/cache.go
vendored
@@ -21,23 +21,24 @@ type CacheFS struct {
|
||||
type CacheHandler func(*vfs.FileInfo, cachestate.CacheState) bool
|
||||
|
||||
// New creates a new CacheFS. fast is used for caching, and slow is used for storage. fast should obviously be faster than slow.
|
||||
func New(fast, slow vfs.VFS, cacheHandler CacheHandler) *CacheFS {
|
||||
if slow == nil {
|
||||
panic("slow is nil")
|
||||
}
|
||||
|
||||
if fast == slow {
|
||||
panic("fast and slow are the same")
|
||||
}
|
||||
|
||||
func New(cacheHandler CacheHandler) *CacheFS {
|
||||
return &CacheFS{
|
||||
fast: fast,
|
||||
slow: slow,
|
||||
|
||||
cacheHandler: cacheHandler,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CacheFS) SetSlow(vfs vfs.VFS) {
|
||||
if vfs == nil {
|
||||
panic("vfs is nil") // panic if the vfs is nil
|
||||
}
|
||||
|
||||
c.slow = vfs
|
||||
}
|
||||
|
||||
func (c *CacheFS) SetFast(vfs vfs.VFS) {
|
||||
c.fast = vfs
|
||||
}
|
||||
|
||||
// cacheState returns the state of the file at key.
|
||||
func (c *CacheFS) cacheState(key string) cachestate.CacheState {
|
||||
if c.fast != nil {
|
||||
|
||||
Reference in New Issue
Block a user