Apache allows you to cache content to improve website speed as well as reduce server load. But do you know where is Apache Cache stored? Let us look at Apache cache location so you can easily monitor and manage it.
There are two types of Cache supported by Apache, either before or behind Apache server
Before Apache server: In this case, the cache is placed before the server and is checked before the request is sent to Apache. It is faster since there is no need to wait for Apache to process the request. However, it is less secure because there is no authentication involved. So it is suitable for caching content that doesn’t require authentication – documents, images, videos, tutorials, etc.
Behind Apache Server: Here the request is sent to Apache server first, which will fetch the content from cache before serving it to the user. Although it is slower, it is more secure.
Where is Apache Cache Stored?
By default, Apache cache is located at
You can see its contents with the command
$ ls -la /var/cache/apache2/mod_cache_disk/
This will show you the cached items
user@localhost:/var/www/html# ls -la /var/cache/apache2/mod_cache_disk/ total 20 drwxr-xr-x 5 www-data www-data 4096 Feb 1 21:43 . drwxr-xr-x 3 root root 4096 Jan 6 03:20 .. drwx------ 3 www-data www-data 4096 Feb 1 21:42 2 drwx------ 3 www-data www-data 4096 Feb 1 21:42 T
Initially, it will have only a few items. As your website grows, it will grow in size.
How to Clear Apache Cache?
Over time, your cache will grow in size and start consuming a lot of resources. Here’s how you can clear cache contents.
- Stop Apache Web Server
$ /etc/init.d/apache2 stop [Debian or Ubuntu]
$ apachectl -k graceful-stop [RHEL, CentOS or Fedora]
- Run the Apache utility to flush cache
$ htcacheclean -r
- Restart Apache web server
$ /etc/init.d/apache2 start [Debian or Ubuntu]
$ apachectl start [RHEL, CentOS or Fedora]
Make it point to clear you cache regularly, to avoid stale cache items, and also prevent it from consuming too much memory/disk space.
That’s it! Now you know where is Apache Cache stored.