what is caching & full page cache?
if apache server gets a request to sends to database through php.
the backend process also called as server response time or ttfb.
to avoid this
web server caches pages which frequently serving from database without any changes.
caching the page (dynamically generated) and stores it as static page for a time TTL setby server admin while configuring.
opcode cache, mysql object cache. page cache.
in wordpress it’s done w3tc, supercache by php.
but webserver lightweight and faster than php in most cases.
you can also try nginx as reverse proxy for apache caching
#1. Update package dependencies & install apache utils
apt-get update && apt-get install apache2-utils
#2 enable mod cache , cache disk expires headers modules
enable mods if not available then install.
sudo a2enmod cache
sudo a2enmod cache_disk
sudo a2enmod expires
sudo a2enmod headers
restart the apache server
sudo systemctl restart apache2
#3 edit the apache 2 config
sudo nano /etc/apache2/sites-available/example.com.conf
CacheQuickHandler offCacheLock onCacheLockPath /tmp/m
od_cache-lockCacheLockMaxAge 5CacheIgnoreHeaders
Set-Cookie<Location />
CacheEnable disk CacheHeader on
CacheDefaultExpire 800
CacheMaxExpire 64000
CacheIgnoreNoLastMod On ExpiresActive on
ExpiresDefault A300</Location>
#3.1 understanding cache variables
location & size of the cache
if cache size is set to toohigh (checking the request in cache slower than without implementing cache)
Location of the hdd/SSD or ram
read& write speeds
hdd 100mbs
SSD 500mb
SSD nvme 3gb/s
ram 16gb/s
if cache size is lesser, say 300mb,
it’s better to use ram, if available,
cost of 1gb ram in cloud hosting $10* per month.1
gb SSD $1*permonth.(checkout gce ,AWS, do price calculator)
cache TTL or expiry: based on how frequently content changes, for WordPress blogposts
1hour not a issue,
dynamic sites it should be very lower, in minutes also called as microcaching in nginx
#4 check syntax errors & restart the apache server
sudo apachectl configtest && service apache2 reload
caching strategies
Cache Behind Web Server
front end cache serves without checking the server, php,MySQL, by linux sendfile () option.
Cache in Front of Web Server
If CacheQuickHandler is set to On, then request go to apache then cache, faster than without cache, slower than frontend rache.
Nginx fastcgi cache vs varnish
inorder to use fastcgi in apache you should install nginx as reverse proxy.
varnish is old & popular.but with new technologies like nginx fastcgi less used.
varnish cache: apache serves plain html pages
without css&js in hight loads.