Caching with Apache web server

The Apache2 web server is a very compact, fast and efficient web server. But sometimes there are a large number of requests per second and there it is not a good idea to run the code for the site every time. If you have many equal requests, then you can start caching. Apache2 supports caching and this enhance the performance dramatically.


Caching is a technique, where the result of a request is stored somewhere. If someone needs exact the same response, Apache can use this stored response instead of compute a new one. The main usage of caching is to store results that are used very often. Apache2 supports two different methods:

  • mod_disk_cache
    With disc cache, already processed results are stored on the hard disk of the server. This is slow, but you can store a lot, because the hard disk has a lot of memory.
  • mod_mem_cache
    With memory cache, already processed results are stored into RAM memory. This memory is fast, but a web server only has a limited RAM, so it is a good idea to use it with care.


You have to install the following Apache2 mods:

  • mod_cache
  • mod_disk_cache or mod_mem_cache

Before you install a module, you can check in you mods-avaliable directory if it is already installed:

if it is not yet activated, you can do it the following way:

or if you like memory caching:

The modules are active after a reboot of your web server.


There are different configurations, which depends on which caching method you have choosen.

Disk Cache

You can find the disc cache configuration file here:

At this file you should check if “CacheEnable disk /” is commented.

Mem Cache

You can find the mem cache configuration file here:


With caching enabled you should get a better response time of your web server, especially if there is a lot of traffic.

(Visited 471 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *