How to Install Apache mod_disk_cache


how to install mod_disk_cache

Apache allows you to cache content, thereby improve website speed and reduce server load. You can cache content in memory (using mod_mem_cache) or disk (using mod_disk_cache). Memory-based caching is faster but resource intensive, unlike disk-based caching that is reasonably fast and consumes less resources. In this tutorial, we will look at how to install Apache mod_disk_cache.

 

 

How to Install Apache mod_disk_cache

Here are the steps to install Apache mod_disk_cache. By default, mod_disk_cache is already installed in Apache. You just need to enable and configure it. You will find its settings at “/etc/apache2/mods-available”

 

Configuring mod_disk_cache

Open mod_disk_cache configuration file in a text editor


$ sudo nano /etc/apache2/mods-available/disk_cache.conf

 

Look for the following lines


<IfModule mod_disk_cache.c>
 CacheRoot /var/cache/apache2/mod_disk_cache
 #CacheEnable disk /
 CacheDirLevels 5
 CacheDirLength 3
</IfModule>
  • CacheRoot – location of cached content
  • CacheEnable – flag to enable/disable disk cache
  • CacheDirLevels – determine cache structure, how many directories to be created
  • CacheDirLength – how many characters to use for directory name

 

Enable mod_disk_cache

Next, enable mod_disk_cache and restart Apache server


$ sudo a2enmod disk_cache
$ sudo service apache2 restart

 

That’s it! This is how to install Apache mod_disk_cache

 

How to Clear Apache Cache

Over time, your cache will grow in size and may cause performance issues. In such cases, you can stop Apache server, clear Apache cache and restart it

Stop Apache Server

$ /etc/init.d/apache2 stop [Debian or Ubuntu]
$ apachectl -k graceful-stop [RHEL, CentOS or Fedora]

 

Clear/Flush Apache cache with htcacheclean utility


$ htcacheclean -r

 

Restart Apache Server

$ /etc/init.d/apache2 start [Debian or Ubuntu]
$ apachectl start [RHEL, CentOS or Fedora]

 

 

 

 

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!