Cache is important terminology for website performance. The cache is playing very important role to improve performance of web application.
For example when we are accessing web service and method is accessing data very frequently. The web method response is not change frequently.
At that point if we are accessing each time web service ,it’s very costly in terms of website performance.
At that time we will keep a xml copy of response in cache folder and use it again and again until response will not change. Now our mind have a question how to identify the response or file has been change.You can read this tutorial for more info.
You Can also checkout other tutorial of PHP Cache,
- Prevent Browser cache in PHP
- How to Cache XML file in php
- Simple Tutorial Of APC Cache PHP
- Cache-Control HTTP Headers
- How to install APC cache on Wamp
- Create Cache File Depend On File
There are two method to control cache expiration:
- Set expiry date time of file from cache folder.
- File dependent caching(compare file created time of cache file as well as source file).
Below is code to create cache file with fixed expiry datetime.
$path = 'cache/phpflow.xml';
$oriFile = ' phpflow.xml';
if ((!file_exists($path) || time() - filemtime($path) > 60) && $cache = fopen($path, 'w+'))
$cache = fopen($path, 'r');
How To Use PHP Cache Method in HTML file