How to find out if a file is stored in file system caches,

Docs for NSDataReadingOptions state:

NSDataReadingUncached

Hint indicating that the file should not be stored in the file system caches. To read data once and discard this option can improve performance.

It all makes sense. I am curious if there is a way to find out if the file is in the sysem file caches.

For example, if I need to do a large amount of file reading, it might make sense to prioritize reading files that are already in the cache.

+8
caching cocoa
source share
1 answer

I am afraid that we can only allow some assumptions here, since there is no official documentation on this issue.

  • The iOS file system must be a hierarchical file system (HFS), the same as for OS-X (see iOS HFS file system? )
  • HFS uses Unified Buffer Cache (UBC)
  • UBC caches file data in chunks, not the whole file - this is the first point, even if part of the file is cached, you cannot know if the entire file is cached
  • There are no APIs or kernel commands for managing UBC content (so this answers your question with NO).

Some interesting reading links:

You have the ability to quickly find file access to map a file to a virtual memory page, as described in the same Apple document.

+4
source share

All Articles