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:
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.
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_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:
a2enmod cache a2enmod disk_cache
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.
You can find the disc cache configuration file here:
At this file you should check if „CacheEnable disk /“ is commented.
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.