Skip to content

Commit 475c367

Browse files
committed
cachefs: Add InvalidateCacheFS interface and extend cacheFS to implement it
1 parent 83ce20f commit 475c367

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

fs.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ import (
3434
"github.com/mailgun/groupcache/v2"
3535
)
3636

37+
// A InvalidateCacheFS is a file system with a InvalidateCache method.
38+
type InvalidateCacheFS interface {
39+
fs.FS
40+
41+
// InvalidateCache invalidates the cache for a path on the FS.
42+
InvalidateCache(ctx context.Context, path string) error
43+
}
44+
3745
// Config stores the configuration settings of your cache.
3846
type Config struct {
3947
GroupName string // Name of the groupcache group
@@ -49,6 +57,9 @@ type cacheFS struct {
4957
cache *groupcache.Group
5058
}
5159

60+
// Statically declare that cacheFS satisfies InvalidateCacheFS.
61+
var _ InvalidateCacheFS = (*cacheFS)(nil)
62+
5263
// Open opens the named file.
5364
//
5465
// When Open returns an error, it should be of type *fs.PathError
@@ -176,3 +187,8 @@ func New(innerFS fs.FS, config *Config) fs.FS {
176187
})),
177188
}
178189
}
190+
191+
// InvalidateCache invalidates the cache for a path in the filesystem.
192+
func (cfs *cacheFS) InvalidateCache(ctx context.Context, path string) error {
193+
return cfs.cache.Remove(ctx, path)
194+
}

0 commit comments

Comments
 (0)