开发者 | dartiss |
---|---|
更新时间 | 2011年3月14日 16:12 |
捐献地址: | 去捐款 |
PHP版本: | 2.0.0 及以上 |
WordPress版本: | 3.1 |
wp-contents/uploads
directory named plugin_cache
. This will store any cached files.
The main functions to be aware of are plugin_cache_read
and plugin_cache_update
. The read and updating functions are seperate to allow for the files to be "stripped down" before being saved, allowing for improved performance. However, if changes are not necessary then the plugin_cache_read
function can perform the entire caching procedure by itself.
plugin_cache_read
The function plugin_cache_read
has 4 parameters...
file key : This is a unique key to identify the cached file. Often, just the filename would be sufficient, but if you need to differentiate between different versions of the same filename (e.g. a news feed which may contain different numbers of entries) then extra data can be added.
filename : This is the filename of the file that you wish to read if a cache doesn't exist. This is optional - if no cache is found and a filename hasn't been specified, then nothing will be returned by the function. This allows you to fetch the file yourself.
timeout : This is the number of hours after which you wish the cache to be updated. Specifying this causes the function to also perform the same processing as plugin_cache_update
.
prefix : This is an optional parameter and allows you to specify a prefix that will be added to the cache filename. This is useful is plugins wish to identify their cached files with a unique prefix - the plugin can then, additionally, provide the option to delete its own cache files.
So, specifying a filename but NOT a timeout will cause the file to be fetched - either from cache or not. Specifying a timeout and a filename will mean that the file will be fetched and then updated in the cache.
The function will return an array containing the following data...
cache_update : Does the cache need updating? This is relevant if you are using the plugin_cache_update
function, as you can use it to determine whether you need to call it or not. It contains either Y
or blank.
data : This is the returned file contents. If it was not fetched from cache and you did not specify a filename, then this will be blank.
An example of usage would be...
$return=plugin_cache_read("test","http://www.artiss.co.uk/feed",3,"test");
This would fetch the feed from my site, updating the cache and giving it a timeout of 3 hours. The cache file would begin with the prefix "test_".
plugin_cache_update
The function plugin_cache_update
has 4 parameters... file key, file contents, timeout and prefix.
Only the last parameter is optional and all except the second are the same as with plugin_cache_read
. The second parameter is the file contents rather than the filename itself.
An example would be...
$return=plugin_cache_update("test",$data,3);
This would update the cache with the contents of $data
for 3 hours.
wp-plugin-cache
folder to your wp-content/plugins/
directory.It has been tested and been found valid from PHP 4 upwards.