We made this PHP cache function for speeding up websites. Take a read and see how important caching is.
This simple PHP file based caching PHP function is a really good way of caching data returned from api’s or data feeds in PHP. It’s flexible and can be used in many scenarios to speed up your web app. It’s not perfect and it’s not the best method of caching but it’s quick and easy to implement using just file based .txt files.
Just make sure you include the file and also set your cache folder to permissions for writing (CHMOD 777).
Include the function.
Call the function into a variable with the appropriate parameters.
- $key is the name of the cache, give it a unique name.
- $call_this is the PHP function name that will return the data to be cached. Note this must return data.
- $call_this_params is the variable we pass to $call_this.
- $expire is the number of seconds till expiry (default 1 hour).
- $html_comment specifies whether or not to place an html comment with cache details (default true).
$data = pk_cache($key, $call_this, $call_this_params, $expire = 3600, $html_comment = true);
Echo out the data into the HTML.
If you have any suggestions or questions feel free to comment about the PK Cache.
Please don’t forget to give credit where credit is due and link to Pretty Klicks.