James John – Software Engineer

Create a Fast Loading Dynamic PHP Site Using PHP Caching

Create a Fast Loading Dynamic PHP Site Using PHP Caching

Query not your database too much and leave it to rest, which will absolutely make your page load as fast as a local html file in your PC
https://donjajo.com/wp-content/uploads/2014/02/eggtimer.gif
WHAT IS CACHING?
This is the act of storing a data for future retrieval in a faster way.
WHERE IS CACHING NEEDED?
Well, I should say when you are having a static website; there is no need to cache because it does not communicate with database and browsers loads html web pages so fast.
Dynamic site is where Caching is needed in other to load the page so fast and not communicating with your database frequently.
HOW DOES PHP CACHING WORKS?
Below is the coding but let me explain a little bit about it here. There is no big deal about it;
  • On page load, save the HTML source code of the page in a file as a .html file extension in a specific directory which you will specify here

  •   On next page load, check if the cache file of the current page exists
  •   If it exists, check if the expiration (which I set 3 minutes as default) has reached because a cache file cannot be forever, you need to delete it and create another so that new contents from the database can be updated in the page.
  •   Now if the expiration time has reached, delete the file and create new one else load it and stop other codes from executing
THE PHP CODE

HOW TO IMPLEMENT PHP CACHING CLASS INTO YOUR PAGE

James John

Software Engineer