How does Commons VFS Cache work?

I am trying to learn how to use Apache Commons VFS2.

I read the entire document that I could find, and I am already familiar with the API, but still there is one thing that I do not quite understand.

How does the cache mechanism work? In particular:

  • I do not understand the difference between the cache strategy and the FilesCache interface. What is used when?

  • The document here says: http://wiki.apache.org/commons/VfsCacheStrategy ... that there are 3 possible cache strategies, and each one is explained in detail. I get the "simplest" on_call strategy, but the other two do not. For example, if we choose the MANUAL strategy, it says that "you need to use fileObject.refresh () to update your object using the file system." But what exactly does this mean? Does this mean that if I write bytes to the FileContents of this FileObject, they will not actually be written until I close the file object or call the update? What if I have 2 FileObjects files that are resolved from the same URI and I delete () the first? Will the second exists () method still return true since file objects are cached?

When I try to play with different cache strategies locally on my machine, I really do not find differences in behavior. They all behave the same, and the files are always synchronized with FS (or at least this does not mean that they are not).

+5
source share
1 answer

CacheStrategy basically controls the re-synchronization of metadata inside a FileObject between multiple calls. FileObject decides when to update its view of the world.

It will call refresh() each time you resolve , or it will call refresh() before each call to the FileObject method (via the OnCallRefreshFileObject decorator) or never automatically.

refresh() sets the FileObject state to a detached state most of the time, so it is read fresh when the next action is checked using attach() .

This is mainly due to metadata, such as attributes and children, I don’t think there is any file system provider that actually caches the content.

FilesCache actually responsible for caching instances of FileObject inbetween resolveFile() calls. Thus, if you manage to resolve or go to the same file, you will also get the same instance of the Java object (if you are not using NullFilesCache or some entries LRUFilesCache expired in the LRUFilesCache cache).

+4
source

Source: https://habr.com/ru/post/1210449/


All Articles