This includes:
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.
package | midcom.services |
---|
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.
string
The script cache identifier to load (without the trailing .php).string
The code to add to the cache, it must not include the php
opening/closing tags, they will be added automatically during cache file creation.boolean
Indicating success.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.
string
The namespace to use.string
The local identifier to use.string
The full cache file identifier or false on failure.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.
string
The script cache identifier to load (without the trailing .php).int
The 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.boolean
Indicating success.