Create apache2 cache system:


On Ubuntu apache web server, the caching system is disabled by default.
It is recommended to leave it off, it can create conflicts where pages are out of sync from source, cache and end user browsers.
Also given I use very low latency storage (Intel Optaine / 3DXpoint), the copying to the cache then sending to the user takes longer then just sending to the user directly from 3D-Xpoint.
Plus the cache expires, having to reload everything, and next cloud is partially slow for updating the cache.
===============================================================================================================================================================================================
If you want to continue, follow this guide:

  1. You can only have a cache disk, the cache file is much more complicated (you have to manually specify each file, rather then just load everything to the cache).
    I will create a ram disk (using tmpfs) by:
    1. sudo mkdir /opt/ramdisk
    2. sudo mkdir /opt/ramdisk/apache2-cache-disk
    3. sudo nano /etc/fstab
      1. *Add this: tmpfs /opt/ramdisk/apache2-cache-disk tmpfs rw,nodev,nosuid,size=2G 0 0
    4. Save and reboot.
  2. tmpfs will cache to swap if enabled, but has a maximum amount set where ramfs will grow forever.
  3. When rebooting the server, enable the cache by:
    1. sudo a2enmod cache
    2. sudo a2enmod cache_disk
  4. As well, go to the /etc/apache2/mods-enabled/cache_disk.conf and have the file look like this:
  5. Save the file and then run this commands:
    1. sudo systemctl restart apache2
    2. sudo systemctl start apache-htcacheclean
Your file system cache should now be running!

You can see the contents of the cache grow using btop, it will take a few minutes while users are browsing the website.
It will grow somewhat quickly if its on the internet and bots are going through the website.

=============================================================================================================
I need to disable the cache! Run these commands:
  1. sudo a2dismod cache_disk
  2. sudo a2dismod cache
  3. sudo reboot
  4. sudo nano /etc/fstab
    1. Comment or remove the ramdisk line for apache:
    2. #tmpfs /opt/ramdisk/apache2-cache-disk tmpfs rw,nodev,nosuid,size=2G 0 0
  5. Save and reboot again.
It should now be disabled.

==============================================================================================================
Sources:

https://www.serverlab.ca/tutorials/linux/web-servers-linux/improve-website-performance-by-enabling-caching-in-apache/
https://askubuntu.com/questions/296038/what-is-the-difference-between-tmpfs-and-ramfs#296043
https://unix.stackexchange.com/questions/66329/creating-a-ram-disk-on-linux
https://duckduckgo.com/?q=apache+load+mod&t=vivaldi&ia=web
https://tecadmin.net/how-to-enable-caching-in-apache/
https://httpd.apache.org/docs/2.4/caching.html
https://geekflare.com/disable-cache-in-browsers/
https://www.geeksforgeeks.org/disable-browser-caching-with-meta-html-tags/
https://httpd.apache.org/docs/2.4/mod/mod_file_cache.html
https://www.simplified.guide/apache/enable-disable-module


Date: July 21st 2024.

Back