Resources | Resources |



IFile cache feature

The IFile interface provides file caching. Caching can be used to improve performance in select instances when file reading, writing, or seeking is considered frequent enough on certain files. See IFILE_SetCacheSize() function in the for more information.

Brew MP file caching code only caches a file for a particular instance of IFile. After the IFile interface is released, so is the cache. When the IFILE_SetCacheSize call is made, Brew MP immediately allocates a cache buffer of the given size and reads the amount of the file specified in the call into the buffer.

The following are suggestions in the use of caching:

  • For simple sequential access to a file, the lower-level file system generally does some level of file caching that provides byte-by-byte access to the file without going to NAND for each byte. The extra layer of Brew MP file caching, though it might avoid kernel transitions, is not likely to improve performance in this case.
  • Because the cache for an IFile is released when the last release is done on an instance of IFile, repeatedly opening, caching, and releasing a file can probably hurt performance due to the repeated loading of the cache.
  • Because the cache is per IFile instance, opening and caching the file twice results in the file being read from NAND twice, and two copies of the file cache in memory, rather than one. If a file is cached, you should share a single instance of the IFile rather than creating two.
  • Because calling IFILE_SetCacheSize() immediately reads from the file to fill the cache, do not call it until you are actually ready to read from the file. Doing so can introduce a delay in your application while the cache for a file that may never be accessed is filled.
  • One place where caching may improve application performance is for a file that is accessed randomly throughout the life of the application (similar to a resource file). In this case, having an IFile instance that is cached and open for the application lifetime is likely to help. This is what Brew MP does internally with resource files accessed via the IShell_LoadResXxxxx family of functions. Although even in this case, you should measure performance with and without caching to see if it really does provide performance improvement.