8

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 files which already reside in the cache.

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
  • 1
    What's the idea behind priorities? You need to read 100 files, 10 are cached with 1s read time, 90 uncached with 2s read time. You'll always find out that it takes 190s to read them all, no matter what the read order was. – ott-- May 17 '12 at 21:54
  • 2
    Ah, but if I happen to read the uncached ones first, evicting the others from the cache, then all reads end up uncached, taking 200s in total – Mike Abdullah May 18 '12 at 09:13

1 Answers1

4

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.

Community
  • 1
  • 1
MrTJ
  • 13,064
  • 4
  • 41
  • 63
  • Sorry for the confusing tags there that someone added, I'm interested in this for all Cocoa platforms, not just iOS. I figure they behave the same in this case though, as the filesystems are basically the same. – Mike Abdullah May 25 '12 at 23:21
  • So when you say there's no API to *control* the contents of the UBC, you're including any sort of inspection as part of that right? i.e. I don't want to edit the cache in any way, merely find some information about it; and there's no API for that either, right? – Mike Abdullah May 25 '12 at 23:24
  • I answered from the iOS point of view. Under that OS there are surely no public APIs to gather more information about the cache. I collected all publicly available information that is not under NDA. – MrTJ May 27 '12 at 12:29
  • There is some further information [here](https://developer.apple.com/library/prerelease/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/PerformanceTips/PerformanceTips.html) – Paul de Lange Jul 14 '14 at 02:28