Doing Things Wrong

Server Caching Madness

Well, it's that time of year again, time to renew the web hosting. And for those of you that don't know, that has become a lot more expensive than it used to be. Fifty dollars a year is now several hundred. Not to mention the price of domain names has gone up ten-fold.

And I just found out that the nice folks at PayPal disabled all my Support buttons, and I never got a notice (although that may be my fault.) In any case, it is all working again now, so if you would like to make a small donation to help defray these costs, it would be greatly appreciated.

I recently set up a new account on Bluehost to set up another website using my simple framework on WordPress. Simple is developing into something far more powerful than I originally intended.

This site is grafted onto an account that is over 10 years old now. After working with the new account a while, I began to see differences between the old and the new. Specifically, the new account was subject to server caching of php pages. This can be quite maddening for a developer, as your changes just don't show up, at least not until the cache gets stale and refreshes.

First, I found that Bluehost had sneakily installed a caching plugin in WordPress. Look for anything in the mu-plugins folder and delete it, unless you put it there yourself. But that didn't fix the problem.

I spent a long time 'chatting' with Bluehost's tech support about this. They were fairly knowledgeable ( so am I ) and very skilled at dancing around the subject without actually lying. They claimed to do something, but nothing changed, and they basically would not admit that there was any server caching, and wasted a lot of my time on irrelevancies. But they did accidentally drop one useful bit of information.

There is a nocache directive that can be added to any request that will turn off the server caching and give you a fresh copy of what you are requesting. No doubt intended exactly for developing. Just add ?nocache to the end of any url; &nocache if there are already parameters. For example:

https://luthierylabs.com/?nocache

Now this site doesn't actually have the caching problem, it is grandfathered-out of caching. If they turned on caching on existing accounts, all kinds of things would break, and they would have a lot of irate customers. Also, caching is disabled when you are logged-in to the WordPress dashboard, otherwise it wouldn't work at all. I figured this all out while chatting with tech support, so it wasn't a complete waste of time. I also figured out three ways to defeat server caching:

The first I have already described - just add ?nocache to your url. You can also do this in html links. I was linking to a particular php file who's output was assembled from other files. Although the php file didn't change, the source files did, but since the server cached the output based on the date of the php file, your changes were lost until the next cache flush. Doing this in any html link will cure the problem, but just for that one link.

To make this happen for all file requests, add the following line to the end of your .htaccess file:

RewriteRule (.+) $1?nocache [QSA]

.htaccess is a plain text file typically found in the root of your account's file system, you can edit it through ftp with any text editor. It controls how requests are handled prior to handing them off to the server. The syntax is incredibly arcane, but all you need to do is paste this line on at the end of the file. The new rule simply appends the nocache directive to every request. Goodbye caching!

Finally, a sneaky way to solve the problem for a single file is to simply change its date on every access. This is easily done on a Unix/Linux system by incorporating the following line in your WordPress theme's functions.php:

touch( getcwd() . "/path/file" );

touch is a *nix utility that will change the file date. getcwd() returns your current working directory, the root of your account. Change path to the path to your file, and file to the filename.

So there you have three ways to defeat server caching. I am using the second one, as it defeats ALL server caching for all files and requests all the time. Much like my fix for Gutenberg's tool tips, I could automate this if I find someone has undone my change, but I doubt that will be necessary.

I should mention, all of this assumes apache running on Linux.

I still recommend Bluehost as the best host out there. However, the truth is that most web hosts, including Bluehost, were bought up by Endurance International Group (EIG). This includes HostGator, but not GoDaddy. All the companies that were bought-up were converted to Bluehost's model, so they are all exactly the same except for the name, and any of them would be just as good and just as bad. The only major alternative left - GoDaddy hosting - is awful, especially for WordPress or any other kind of active site. Well, that was the case years ago, maybe they got better, I don't know, and I'm not spending any of my money to find out.


Audiovox Gibson-style Bass
Audiovox 736 Replica Bass
Audiovox Gibson-style Guitar
Audiovox Danelectro-style Bass
Audiovox Fretless Bass
Audiovox Electric Upright Bass
Audiovox Strat-style Guitar
Audiovox 12-string Guitar
Audiovox Ukulele Bass
Audiovox Mandolin
BC Rich "Osprey" Bass
Brownsville Violin Bass
Cowbell Bass
Danelectro Pro-1 Bass
Danelectro "Super-63" Guitar
Danelectro Silvertone 1457 Rescue Guitar
Danelectro Longhorn Guitar
Danelectro Silvertone U-1 Guitar
Danelectro Companion Guitar
Danelectro Silvertone 1443 Bass
Danelectro '67 Hornet Guitar
Fender Jazzmaster Bass 1
Fender Jazzmaster Bass 2
Fender Jazzmaster Bass 3
Fender Stratocaster Bass 1
Fender Stratocaster Bass 2
Fender Stratocaster Micro Bass 1
Fender Stratocaster Micro Bass 2
Fender Stratocaster Fretless Bass
Fender Stratocaster Bass VI
Fender Stratocaster Bass IV
Fender Stratocaster 12-string Guitar
Fender Stratocaster Uke Bass
Fender Squier Stratocaster Guitar
Fender Telecaster Bass
SX Precision Bass
Gibson Fenderbird Bass 1
Gibson Fenderbird Bass 2
Gibson Reverse Fenderbird Bass
Kubicki Bass
Schwinn Stingray Bass
Mosrite Bass
Rickenbacker 325 Guitar
Rickenbacker 325 Bass 1
Rickenbacker 325 Bass 2
Rickenbacker 325 Bass 3
Rickenbacker 4001 Bass 1
Samick SG450 Guitar
Danelectro Pro-1 Guitar
Danelectro Silvertone 1448 Guitar
Danelectro '63 Guitar
Danelectro Silvertone 1457 Guitar
Harmony H617 Bobkat
Danelectro Silvertone 1450 Guitar
Harmony Silvertone 1478
Danelectro Silvertone 1472 Amplifier
Danelectro Longhorn Bass

A while ago I said I couldn't find where the new Nivo Slider slideshow plugin (above) keeps its data. That's because it doesn't keep it anywhere. It generates each slideshow on the fly from scratch, with lord-knows how many database calls. I suspected that it was grossly inefficient, and I was right.

Printed from luthierylabs.com