The Linux system provides us with the solution, that is, the Tmpfs file system, TMPFS can use the memory directly, while not enough memory to use the swap partition to store. Also note that TMPFS is not persistent, restart data does not retain, please be sure to note, but we only use it to store cached files, even if the file is lost does not affect the site access, there is no risk.
/dev/shm/is a device file that uses the Tmpfs file system (note: Under CentOS and Redhat, the SHM directory is a link to the/RUN/SHM directory, under the Ubuntu system Tmpfs file system corresponds to/run/ The SHM directory can be viewed using the DF command because the/dev/shm/directory is not on the hard drive but in memory, which is called TMPFS. You can see by command DF, tmpfs default size is half of the physical memory, of course, can also be adjusted according to the actual situation.
First, create a directory for WordPress cache files Wpcache
Mkdir/dev/shm/wpcache
Grant Read and Write execution permissions
chmod 1777/dev/shm/wpcache
Mount Tmpfs to the cache directory generated by the WordPress cache plugin
Mount--bind/dev/shm/wpcache/home/wwwroot/trojansun.com/wp-content/cache Ls-ld/dev/shm/wpcache
Returns something similar to the following description Mount success
DRWXRWXRWT 3 www. 22:50/dev/shm/wpcache
At this time, the cache plug-in will regenerate the static paging file, after a period of time, through the command DF can find the use of TMPFS.
Two issues to be noted:
1. According to the actual situation (memory size, number of articles) to adjust the WordPress cache plug-in cache page expiration time, otherwise it will occupy too much memory;
2. Note that you add a swap partition to prevent memory from being available for standby, 4G physical memory to set the swap partition size to 2G.