Pages of web applications are dynamically generated. Code is executed to process user input and generate output every time a page is requested. There are a lot of overheads involved in generating dynamic pages, especially when compared to serving static HTML files. The code may connect to a database, perform computationally expensive calculations, process files, and so on. At the same time, being able to generate pages with code is exactly what makes a web site dynamic and interactive. Wouldn't it be great if we could get the best of both worlds? This is what caching does, and it's a feature that is implemented in most sites with medium to high traffic.
When a page is requested, caching works by storing the generated HTML of the page and reusing it later when the same page is requested again. This cuts a lot of overheads by avoiding the need to generate the same page over and over. Of course, cached pages are not stored forever. When a page is cached, an...