Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

rc: add fscache/clear and fscache/entries to control the fs cache #4811

Nick Craig-Wood657be2ace529
diff --git a/fs/rc/cache.go b/fs/rc/cache.go
index 958a1db3f..989e9ffe7 100644
--- a/fs/rc/cache.go
+++ b/fs/rc/cache.go
@@ -43,3 +43,48 @@ func GetFsAndRemoteNamed(ctx context.Context, in Params, fsName, remoteName stri
func GetFsAndRemote(ctx context.Context, in Params) (f fs.Fs, remote string, err error) {
return GetFsAndRemoteNamed(ctx, in, "fs", "remote")
}
+
+func init() {
+ Add(Call{
+ Path: "fscache/clear",
+ Fn: rcCacheClear,
+ Title: "Clear the Fs cache.",
+ AuthRequired: true,
+ Help: `
+This clears the fs cache. This is where remotes created from backends
+are cached for a short while to make repeated rc calls more efficient.
+
+If you change the parameters of a backend then you may want to call
+this to clear an existing remote out of the cache before re-creating
+it.
+`,
+ })
+}
+
+// Clear the fs cache
+func rcCacheClear(ctx context.Context, in Params) (out Params, err error) {
+ cache.Clear()
+ return nil, nil
+}
+
+func init() {
+ Add(Call{
+ Path: "fscache/entries",
+ Fn: rcCacheEntries,
+ Title: "Returns the number of entries in the fs cache.",
+ AuthRequired: true,
+ Help: `
+This returns the number of entries in the fs cache.
+
+Returns
+- entries - number of items in the cache
+`,
+ })
+}
+
+// Return the Entries the fs cache
+func rcCacheEntries(ctx context.Context, in Params) (out Params, err error) {
+ return Params{
+ "entries": cache.Entries(),
+ }, nil
+}
diff --git a/fs/rc/cache_test.go b/fs/rc/cache_test.go
index ca5a1cd8e..e81d493aa 100644
--- a/fs/rc/cache_test.go
+++ b/fs/rc/cache_test.go
@@ -80,4 +80,35 @@ func TestGetFsAndRemote(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, f)
assert.Equal(t, "hello", remote)
+
+ t.Run("RcFscache", func(t *testing.T) {
+ getEntries := func() int {
+ call := Calls.Get("fscache/entries")
+ require.NotNil(t, call)
+
+ in := Params{}
+ out, err := call.Fn(context.Background(), in)
+ require.NoError(t, err)
+ require.NotNil(t, out)
+ return out["entries"].(int)
+ }
+
+ t.Run("Entries", func(t *testing.T) {
+ assert.NotEqual(t, 0, getEntries())
+ })
+
+ t.Run("Clear", func(t *testing.T) {
+ call := Calls.Get("fscache/clear")
+ require.NotNil(t, call)
+
+ in := Params{}
+ out, err := call.Fn(context.Background(), in)
+ require.NoError(t, err)
+ require.Nil(t, out)
+ })
+
+ t.Run("Entries2", func(t *testing.T) {
+ assert.Equal(t, 0, getEntries())
+ })
+ })
}