• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Apache 2.4 Disk Cache : How To Use And Why Not To Use

By Abhishek Ghosh October 17, 2017 5:51 pm Updated on October 12, 2018

Apache 2.4 Disk Cache : How To Use And Why Not To Use

Advertisement

When you are using Apache2 server, then you are well aware of the fact that Apache2 is intended to be powerful, enterprise grade web server. Apache 2.4 disk cache is powerful cache and is content aware. Many users while trying to use old directives face no caching – that is intended to escape errors on many servers which are not closely managed. As Apache 2.4 has undergone many changes like HTTP/2 Server Push, many old features with vulnerabilities needed to be escaped and pushed for the managed, well monitored servers. Here is how to use Apache2 disk cache and also our opinion why, when not to use.

 

Apache 2.4 Disk Cache : How To Use

 

This article is for those who have installed Apache2 in our described way on server running newer operating system like Ubuntu 16.04 LTS.

First enable module cache :

Advertisement

---

Vim
1
a2enmod cache

You will receive the message :

Vim
1
2
3
Enabling module cache.
To activate the new configuration, you need to run:
  systemctl restart apache2

Restart Apache :

Vim
1
systemctl restart apache2

Create a directory for Apache2 :

Vim
1
mkdir -p /var/apache-cache

Give proper ownership :

Vim
1
2
3
chown www-data /var/apache-cache
chgrp www-data /var/apache-cache
ls -al /var/apache-cache

Enable module cache_disk :

Vim
1
sudo a2enmod cache_disk

You’ll receive this message :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
Considering dependency cache for cache_disk:
Module cache already enabled
Enabling module cache_disk.
Enabling external service apache-htcacheclean
Synchronizing state of apache-htcacheclean.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable apache-htcacheclean
insserv: warning: current start runlevel(s) (empty) of script `apache-htcacheclean' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `apache-htcacheclean' overrides LSB defaults (0 1 6).
The service will be started on next reboot.
To activate the new configuration, you need to run:
  systemctl restart apache2
  systemctl start apache-htcacheclean

Run the needed commands to activate cache_disk :

Vim
1
2
systemctl restart apache2
systemctl start apache-htcacheclean

Change directory to /etc/apache2/sites-available :

Vim
1
2
cd /etc/apache2/sites-available
ls -al

Taking that your website is using HTTPS with Let’s Encrypt, your file for current vhost can be anything which you know, like :

Vim
1
2
000-default-le-ssl.conf
default-ssl.conf

Open the file, the files usually starts with :

Vim
1
2
3
4
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
...

Exactly like our guide on OSCP Stapling configuration on Apache2.4, you’ll add the directives after and before :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CacheQuickHandler off
CacheLock on
CacheLockPath /var/apache-cache
CacheLockMaxAge 5
CacheIgnoreHeaders Set-Cookie
 
<Location />
    CacheEnable disk
    CacheHeader on
    CacheDefaultExpire 800
    CacheMaxExpire 64000
    CacheIgnoreNoLastMod On
    ExpiresActive on
    ExpiresDefault A300
</Location>

Save the file and run configuration test :

Vim
1
sudo apachectl configtest

Upon success, restart Apache :

Vim
1
sudo systemctl restart apache2

You’ll see files written at /var/apache-cache. htcacheclean is used to maintain a control over the size of the filesystem that disk_cache uses. Run man htcacheclean or search the web to use it from cron to flush cache on need.

Now for WordPress like CMS, the above configuration will seriously interfere and posts on frontend unlikely to open on click. First the above configuration needs some edit to escape caching like wp-admin or some files with form or special need :

Vim
1
2
3
CacheDisable /wp-admin
CacheDisable /wp-login.php
CacheDisable /wp-cron.php

You need to cache only posts, pages. We need to modify WordPress Permalink from .htaccess or whatever file you use :

Vim
1
2
3
4
5
6
# WordPress Permalink rewrites
RewriteBase /
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

It is more practical to cache selectively the areas you will likely to need least update :

Vim
1
2
3
4
5
6
7
8
9
# Cache the home page
<LocationMatch "^/$">
CacheEnable disk
</LocationMatch>
 
# Cache category pages
<Location /category>
CacheEnable disk
</Location>

 

Apache 2.4 Disk Cache : Why Not To Use

 

Apache-2.4-Disk-Cache-How-To-Use-And-Why-Not-To-Use

These modules are really for fully managed and 24 hours monitored servers. Bugs, security flaws of these modules are common and often need custom fix. Odd HTTP errors not uncommon which needs active monitoring of log files. Most of the users self manage servers. Number of ordinary users of these modules are less. These are better for static websites and really WordPress has lot of ways of caching including adding a reverse proxy server at front running Nginx. It is very difficult to flush the cache after publication of a post.

Tagged With windows set apache service cach size , apache2 cache_disk , apache server not using disk , apache root directory of the disk cache , apache mod_disk_cache NOT mod_mem_cache , apache disk cache , apache cache location windows , apache 2 4 doesn\t write cache , apache 2 4 caching , apache 2 4 cache videos
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Apache 2.4 Disk Cache : How To Use And Why Not To Use

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • WordPress & PHP : Different AdSense Units on Mobile Devices

    Here is How To Serve Different AdSense Units on Mobile Devices on WordPress With PHP. WordPress Has Function Which Can Be Used In Free Way.

  • Ubuntu 16.04 Apache2 HTTP/2, HSTS : Steps + Configuration

    Here Is A Full Working Guided Steps To Setup Ubuntu 16.04 Apache2 HTTP/2, HSTS Easily. Also We Have Supplied, Configuration Files, Commands.

  • How To Install Apache2 on Ubuntu 18.04 With Let’s Encrypt, HTTP/2, HSTS

    Here is Detailed Guide on How To Install Apache2 on Ubuntu 18.04 With Let’s Encrypt, HTTP/2, HSTS With Commands and Configurations For Most Secured Setup.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy