How to know if a file is "stored in the file-system caches"
The docs for NSDataReadingOptions
state:
NSDataReadingUncached
A hint indicating the file should not be stored in the file-system caches. For data being read once and discarded, this option can improve performance.
That all makes sense. I'm curious if there's a way to know if a file already resided in the file-sysem caches.
For example, if I need to perform a large amount of file reading, it might make sense to prioritise reading file开发者_JAVA百科s which already reside in the cache.
I am afraid here we can relay only some suppositions as no official documentation is available on this.
- The file system of iOS is supposed to be Hierarchical File System (HFS) the same as that one of OS-X (see iOS filesystem HFS?)
- HFS uses Unified Buffer Cache (UBC)
- UBC caches file data in chunks rather then the whole file - this is the first point, even if part of the file is cached you can't know whether the whole file is cached
- There are no any APIs or kernel commands to control the contents of UBC (so this answers your question with NO).
Some interesting links to read:
- Testing the UBC
- This guy tried to get some info about the contents of UBC under (jailbreaked) iPhone
- The only control over the file system cache mentioned in the documentation is the same flag you also found.
Your option to ensure that a file can be accessed quickly is to map the file onto a page of the virtual memory as described in the same doc of Apple.
精彩评论