Table of Contents

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 -t tmpfs -o size=1G tmpfs /mywebsite/wp-content/cache/wp-rocket

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 :

tmpfs /mywebsite/wp-content/cache/wp-rocket tmpfs defaults,size=1G 0 0

Comments (8)

Good solution :)

Ah that is really cool! Do you know how big this will typically be? Ie how much space is needed...

Depending on how many page do you have.
It's only html pages, so not a lot of spaces.

Bonjour,

J'hésite entre ces deux serveurs, pour de l'hébergement de sites WordPress, le gain de performances est-il réellement notable avec du SSD ? La durée de vie de ces disques et leur fiabilité me freine un peu. Même si je suppose que 3x300Go en MegaRAID autorique la défaillance de 2 disques sans perte de données...

http://www.soyoustart.com/fr/offres/e3-sat-4.xml
http://www.soyoustart.com/fr/offres/e3-ssd-4.xml

Nicolas.

Bonjour Nicolas,
Justement le SSD est plus fiable par rapport à du disque mécanique, car justement il n'y a pas de pièces ... mécaniques.
Oui en terme d'écriture/lecture la différence est très importante, je te conseille donc le SSD :)

Hello

Thank you for this nice article. What if I have a SSD , is it ok to mount a folder directly into the RAM?

Hi Yaqoub,
If you have a SSD, you don't need to mount it on the RAM.

Thanks for the tip. I did the same thing for my Windows Server 2003 server with Apache installed.

Download SoftPerfect RAM Disk (freeware). Configure a virtual drive V: with 2GB:
https://www.softperfect.com/products/ramdisk/

Download Junction 1.06:
https://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

Mount a folder just like in linux, for instance like this:
junction -s V:Cache c:wwwwp-contentcache

All done. The junction program (and RAM Disk) make sure the server remembers the mount point when you reboot the server.

Related Articles of Page speed and caching
Subscribe to Our Newsletter

Stay in the loop with the latest WordPress and web performance updates.
Straight to your inbox every two weeks.

Get a Faster Website
in a Few Clicks

Setup Takes 3 Minutes Flat
Get WP Rocket Now