Commons VFS 缓存是如何工作的?
How does the Commons VFS Cache works?
我正在尝试学习如何使用 Apache Commons VFS2。
我已经阅读了我能找到的所有文档,并且我已经对 API 有点熟悉了,但仍有一件事我不太清楚。
Cache机制是如何工作的?特别是:
我不明白缓存策略和 FilesCache 接口之间的区别。什么时候用哪个?
这里的文档中说:http://wiki.apache.org/commons/VfsCacheStrategy ... 有 3 种可能的缓存策略,每一种都有详细解释。我得到了 "simplest" on_call 策略,但其他两个我没有。例如 - 如果我们选择 MANUAL 策略,则表示“you have to use fileObject.refresh() to refresh your object with the filesystem”。但这到底意味着什么呢?这是否意味着如果我将字节写入此 FileObject 的 FileContents,在我关闭文件对象或调用刷新之前它们实际上不会被写入?如果我有 2 个从同一个 URI 解析的 FileObjects 而我 delete() 第一个怎么办?由于缓存了文件对象,第二个 exists() 方法是否仍然 return 为真?
当我尝试在我的机器上本地使用不同的缓存策略时,我并没有发现任何行为上的差异。它们的行为都相同,并且文件始终与 FS 同步(或者至少它们不同步并不明显)。
CacheStrategy
basically controls the re-syncing of meta data inside a FileObject
in-between multiple calls. The FileObject
决定何时刷新其世界观。
它会在你每次 resolve 时调用 refresh()
,或者它会在每次 FileObject
方法调用之前调用 refresh()
(通过 OnCallRefreshFileObject
装饰器)或者永远不会自动。
refresh()
大部分时间将 FileObject
状态设置为分离,因此在下一个操作检查 attach()
.
时会重新读取它
它主要与属性和子项等元数据有关,我认为没有任何文件系统提供商实际缓存内容。
FilesCache
is actually responsible for caching instances of the FileObject
inbetween resolveFile()
calls. So you if happen to resolve or navigate to the same file, you will also get the same java object instance (unless you use the NullFilesCache
or the LRUFilesCache
缓存中的一些条目已过期。
我正在尝试学习如何使用 Apache Commons VFS2。
我已经阅读了我能找到的所有文档,并且我已经对 API 有点熟悉了,但仍有一件事我不太清楚。
Cache机制是如何工作的?特别是:
我不明白缓存策略和 FilesCache 接口之间的区别。什么时候用哪个?
这里的文档中说:http://wiki.apache.org/commons/VfsCacheStrategy ... 有 3 种可能的缓存策略,每一种都有详细解释。我得到了 "simplest" on_call 策略,但其他两个我没有。例如 - 如果我们选择 MANUAL 策略,则表示“you have to use fileObject.refresh() to refresh your object with the filesystem”。但这到底意味着什么呢?这是否意味着如果我将字节写入此 FileObject 的 FileContents,在我关闭文件对象或调用刷新之前它们实际上不会被写入?如果我有 2 个从同一个 URI 解析的 FileObjects 而我 delete() 第一个怎么办?由于缓存了文件对象,第二个 exists() 方法是否仍然 return 为真?
当我尝试在我的机器上本地使用不同的缓存策略时,我并没有发现任何行为上的差异。它们的行为都相同,并且文件始终与 FS 同步(或者至少它们不同步并不明显)。
CacheStrategy
basically controls the re-syncing of meta data inside a FileObject
in-between multiple calls. The FileObject
决定何时刷新其世界观。
它会在你每次 resolve 时调用 refresh()
,或者它会在每次 FileObject
方法调用之前调用 refresh()
(通过 OnCallRefreshFileObject
装饰器)或者永远不会自动。
refresh()
大部分时间将 FileObject
状态设置为分离,因此在下一个操作检查 attach()
.
它主要与属性和子项等元数据有关,我认为没有任何文件系统提供商实际缓存内容。
FilesCache
is actually responsible for caching instances of the FileObject
inbetween resolveFile()
calls. So you if happen to resolve or navigate to the same file, you will also get the same java object instance (unless you use the NullFilesCache
or the LRUFilesCache
缓存中的一些条目已过期。