In a
previous post I shared details on how to enable browser caching and since then I got a question on how to do the same, but on the server in order to save system resources.
So I decided to write the current post and give an example on how to enable server caching on Apache using the Apache native modules mod_cache or mod_expires.
To do that with mod_cache and considering the same example - to make the cache expire in 4 hours, you can edit the Apache configuration file (it's usually /etc/apache2/apache2.conf or /etc/httpd/httpd.conf) and add there -
<IfModule mod_cache.c>
CacheDefaultExpire 14400
CacheEnable disk /
CacheHeader on
</IfModule>
Another possibility is to use mod_expires - for example to hide the "output" just from php files for 4 hours -
<FilesMatch ".php$">
ExpiresActive On
ExpiresDefault "access plus 4 hours"
</FilesMatch>