This cache module is desiged to cache files generated by various MidCOM code generation system.

This includes:

  • DBA Intermediate classes (Namespace midcom.dba)
  • Component Manifest (Namespace midcom.componentloader)

The cached scripts are invalidated based on their timestamp. Whenever you load a script from the cache, you have to pass a last modified timestamp to it. This stamp is compared with the modification date of the script file, leading to automatic invalidation in case of outdated script files.

Each cached script must have an identifier, which must be namespaced according to the MidCOM namespacing conventions. Identifiers may consist of any valid filename character, a .php extension is appended automatically on all operations, you should not do that yourself. Namespace and local identifier should be separated by a dash. While adding, you do not need to add the PHP opening / closing tags to the source code, it will be done automatically during cache file creation.

Both the load and add operations will automatically require_once() the script file after successful completion.

Danger, Will Robinson:

You should be aware, that the module in itself has no separation of sites whatsoever, as these scripts are usually valid for an entire installation. In case your application needs to cache scripts per-site or per-content-tree, you need to ensure the uniqueness of the cache identifiers yourself, for example by adding the corresponding GUIDs.



_on_initialize ()

Initializes the cache module, verifying the existence of the script cache directory.

add (string $identifier, string $code, $skip_load)

This call adds a script to the code file cache.

Any existing file will be truncated before the new file is written.

You do not need to add the surrounding php opening / closing tags to the script code, this happens automatically. If the script file has been written out successfully, it will be require'd from there immediately. If writing of the cache file fails, an error is logged, and the script is not executed. If you want a silent fallback in this case, eval the code yourself if false is returned.



stringThe script cache identifier to load (without the trailing .php).


stringThe code to add to the cache, it must not include the php opening/closing tags, they will be added automatically during cache file creation.



booleanIndicating success.

create_identifier (string $namespace, string $local_identifier)

This function creates a filename out of the given namespace and local identifier pair.

Be aware, that this script does not protect against misuse of the system, it is limited to prevent accidential problems like slashes in path names and the like. Namespace and local identifier are separated by a dash.

Any invalid characters are replaced with underscores.



stringThe namespace to use.


stringThe local identifier to use.


stringThe full cache file identifier or false on failure.

invalidate ($guid)

The GUID invalidation wrapper is empty, as cached script files are not bound to any GUID.



invalidate_all ()

The invalidate_all call will just remove all .php files from the defined cache directory.

load (string $identifier, int $lastmodified)

Checks the cache entry against the passed last modification timestamp.

If it is still valid, the corresponding file is loaded by using require_once(). Otherwise, the cache copy is deleted and false will be returned, you have to create the cache entry using the add() call then.

This class supports a variable length argument list: You may add more then one last modified timestamp to the call, in which case only the newest timestamp is taken into account.



stringThe script cache identifier to load (without the trailing .php).


intThe last modification date of the source on which the cached file is based upon. If you pass more then one timestamp, the newest timestamp is used for the comparison.


booleanIndicating success.



string $_cache_dir

The base directory in which we may add script files.