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

This commit is contained in:
Nick Craig-Wood 2020-11-29 11:41:50 +00:00
parent feaaca4987
commit 657be2ace5
2 changed files with 76 additions and 0 deletions

View File

@ -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
}

View File

@ -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())
})
})
}