Web Caching is the caching of data in temporary memory or permanent memory so that we do not have to execute same code over some period of time. Here time period will depend upon how frequently your content change.
Many content we send to client do not change every minute. Here we can save our various resources. We can save our processor from executing that script over some period of time. We can save database resource by avoiding content fetch and showing old content, which is still valid to user. This also saves process time and speed up your page load.
There are various kinds of web caching at different levels. We can cache final content (HTML) generated by executing server side script with static HTML code. There is Browser caching and Proxy caching. Opcode is another kind of caching which is very effective in saving various kinds of resources.
These are all called by different names: Browser caching, Proxy Caching and Gateway caching.
- Content/Data Caching
You will cache HTML source code. Every server side script is transferred to html code sent to browser (client). We can keep the code in cache so that we don not have to run server side script every time a request is made. Server side script is generally not complete in itself. Generally we use database, file system and others for generating html code. With various resources, time saved by this method is measurable.
We need to plan for this kind of caching. We have to check which output to cache and for how long. Smarty kind of template provides good functionality for this caching.
- Caching by Browser and Proxy
Our browser also caches our HTML pages. For this little planning is required for sending proper header with the pages we want to cache.
Proxy caching is suited for large intranet environment.
- OpCode Caching
PHP loads our file and transforms it into opcodes after parsing. This opcode generated can be executed directly. Now we can cache this opcode so that PHP donnot have to parse the page again and again every time a request is made.
In opcode caching, your op code is cached in shared memory or on disk. The program do this kind of jobs are referred as “Accelerators”. Example accelerators are eAccelerators, APC, Zend platform accelerator and xCache.
Why we cache web pages:
We save resources by using web cache. We save database overhead, save CPU usage, time and network bandwidth. When we cache HTML source or opcode we donnot have to interact with database.
When page is used from client side cache then we save bandwidth and time. And by saving there all, we save CPU usage in return.