Cache

The cache system provides an API for caching frequently used data, it provides an interface for user code to cache data and an interface for the DBAL to cache query results.

File
As of 3.0.6-dev the file cache module uses a new improved format for its cache files. These files are read using PHP's file system functions -- namely fread and fgets -- this approach uses less disk I/O as the files are read intelligently mostly line by line. The files contain a PHP header to stop information leak by browsers navigating to the cache folder, this is a last line defence -- the cache folder should really be off limits to clients -- however they are not included as PHP files by phpBB so as not to fragment opcode caches.

Steps:
 * 1) The first line is read and discarded (PHP header)
 * 2) Second line is read (expiration)
 * 3) Processing ends if the expiration is invalid or in the past
 * 4) On SQL cache files the third line (query) is read and discarded
 * 5) The next line (bytes) is read containing the number of bytes of data
 * 6) Processing ends if this is invalid
 * 7) The number of bytes from the previous line is read (data) this is then stored
 * 8) One single byte is read if we don't reach the end of the file now then the data is deemed to be tampered with and discarded

Where:
 * expiration := expiration timestamp
 * query := SQL query
 * bytes := number of bytes in data (except global data includes the length of var)
 * var := Variable name
 * data := Cached data

SQL queries:  (expiration) (query) (bytes) (data)

Normal data:  (expiration) (bytes) (data)

Global data:  (expiration) (bytes) (var) (data) (expiration-n) (bytes-n) (var-n) (data-n) ...