Table of Contents
Last update on
Note : This tricks is only suitable for dedicated servers
A static cache system like WP Rocket stores all the website pages as HTML files.
Without a cache system, when a visitor access a webpage, WordPress loads first. Then, WordPress queries the database to find out which themes and plugins are to load. Finally, it loads the contents of the current page (with database requests).
Sometimes, this mechanism can be very long. SQL language (for communication with the database) is often a bottleneck.
A cache system saves each page directly in the server (HTML files). Thus when a visitor requests a page, the stored file will be directly displayed without any database requests.
The HTML files are stored on the server, displaying the web page will be dependent on the hard drive reading speed (and writing for saving pages).
The best solution is to use SSD for excellent performance compared to HDD.
Problem ? SSD are more expensive, and still less common than mechanical drives.
To take advantage of good performance if you are using a HDD a good solution is to mount the cache folder directly in your RAM. You can save several precious milliseconds with this solution.
It is a common practice we use for files of low importance. Indeed if you restart the server all the data in the RAM is flushed due to the lack of persistence.
The cache files are automatically regenerated, so it’s doesn’t really matter if you loose it.
How do we do this?
We will simply create a tmpfs volume and mount it.
Tmpfs is a filesystem which was originally scheduled to store temporary files (tmp) as the same suggest.
Be careful, the following commands require SSH access and root privileges.
Here is the command:
Mount to create a montage point
- -t to specify filetype
- -o to specify options including size you want to allocate.
You should customize the size options depending how much free ram you have.
Be careful, don’t forget to specify the full path of your cache folder. For instance /var/www/mywebsite
The cache folder will be mounted temporary, and won’t be mounted at the next reboot.
To mount automatically, simply edit the fstab file (/etc/fstab) and add :