Skip to content

Commit f9d647d

Browse files
committed
cachefs: Add RefreshFS interface and extend cacheFS to implement it
1 parent 83ce20f commit f9d647d

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 RefreshFS is a file system with a Refresh method.
38+
type RefreshFS interface {
39+
fs.FS
40+
41+
// Refresh refreshes a path in the filesystem.
42+
Refresh(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 RefreshFS.
61+
var _ RefreshFS = (*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+
// Refresh refreshes a path in the filesystem.
192+
func (c *cacheFS) Refresh(ctx context.Context, path string) error {
193+
return c.cache.Remove(ctx, path)
194+
}

0 commit comments

Comments
 (0)