logo
Powered by QM on a Rpi server
Home
About OpenQM
Sales and Downloads
Help and Support
  QM Help Pages
  KnowledgeBase
  Tip of the Week
  Support Services
  User Group Forum
About
Login

KnowledgeBase 00064: The File Cache

Last updated: 22 Jul 2016
Applies to: All versions
Search  
Top level index       Full Index Search Tips
Previous article     Next article

This article was originally published as a Tip of the Week.

Multivalue applications frequently include loops that call catalogued subroutines that open several files to local file variables. These variables are discarded on exit from the subroutine, closing the files and hence requiring that they must be reopened on the next call of the subroutine.


Caching Files

QM optimises applications that work in this way by use of a caching mechanism. Effectively, when an application closes a file either explicitly or by discarding the file variable, the file is not actually closed at the operating system level. Instead, it is moved into a cache of recently closed files from which it can be reopened at the application level very quickly.

This caching mechanism applies only to the high performance dynamic hashed files, not directory files. The size of the cache is set by the DHCACHE configuration parameter, defaulting to 10 if this parameter is not present. Applications that repeatedly reopen the same files will benefit from making this parameter value large enough to cache a suitable number of files. Beware, however, that setting the parameter significantly higher than needed can have a negative impact on performance.

A separate file cache is maintained in each QM process. A file closed by one process cannot be cached for quick opening in another process.


Flushing the Cache

Some operations require that files are closed at the operating system level. For example, a file cannot be deleted while it is open. To handle this, the cache is automatically flushed when necessary. This includes, if appropriate, flushing the cache in other QM processes. An application can explicitly flush the cache with the QMBasic FLUSH.DH.CACHE statement.


Use of Common File Variables

Although the file cache can provide a significant performance improvement in applications that repeatedly open the same files, it is better to write programs in a manner that avoids the issue completely.

The best way to do this is to put the file variables for the most frequently used files into a common block, opening the files just once and making these file variables available to all programs that need them.


Related Articles

None.



Please tell us if this article was helpful
Very     Slightly     Not at all
Comments
Email (optional)