Is it impossible to manually force a file, and its contents, to be erased from the vfs file cache?

I want to manually evict files from the vfs file content cache using an rclone remote command, but sadly I don't think this is possible?

I know about rclone rc vfs/forget but it only forgets the directory or file metadata cache, not the contents.
The promising looking rclone rc cache/expire command is only for the cache backend, not the vfs file cache.

I don't have a real user problem, per say, I am just doing some testing/benchmarking on rclone mount and I want to be able to force a file and its contents to be expired/purged from the vfs cache. This lets me easily compare cached and non-cached behavior for the same files.

For my testing purposes the workarounds I've tried are:

  • Turning off the cache with --vfs-cache-mode=off. This works but doesn't allow me to then easily compare vfs cached file behavior with non-cached file behavior on the same file. I want to test how rclone mount performs in the cache mode I use it in.
  • Just renaming the file on the remote, doing vfs/forget, and then refreshing the directory. This works but is tedious and requires having the file name constantly in flux.
  • The best workaround for now is just manually deleting the file[s] from the vfs cache directory (~/Library/Caches/rclone/vfs/<remote>/... on macOS by default). For this to work nicely I also need to use vmtouch -e <file> to purge the file from the OS's in-memory file cache. This mostly works fine but I'm always nervous about doing this while rclone is running, particularly if its currently reading from the cache. But maybe it's fine?

To confirm, is there's no way using an rclone remote command (or otherwise) to force a file/directory to be purged from the vfs file cache? Assuming there's no alternative, are there any issues or risks with manually deleting files from the vfs cache directory while an rclone mount is running and might be using them?


There isn't any way through API to do that.

If you delete it from the cache, that will most likely break things as it's expecting it to be there.

I've just been yolo-ing and deleting files directly from the vfs file cache storage area and it seems to work fine, though no idea if I might hit some horrible edge case. Any ideas on what might go wrong? Does rclone keep its own idea of what files are currently cached and not just always rely on the state of whatever is in the vfs file cache directory?

Particularly when I know rclone isn't actively accessing a cached file (confirmed via lsof), deleting it while rclone mount is running appears to work fine with no errors outputted and it behaves as if the file just wasn't in the cache. ¯\_(ツ)_/¯

(but even if rclone was actively reading a file from the cache, presumably rclone would have an open file handler on it which would prevent the system from actually erasing it even if I deleted it)

Not currently. It would be a nice addition though.

Rclone is programmed quite defensively about files in the cache, so it will notice if they get deleted and work around.

There could be corner cases which could cause trouble though. The trouble would mean rclone returned errors (probably IO Errors) to the app using the mount. I don't think rclone should crash ever but I haven't tested that extensively!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.