Cache, a Web Developer’s Friend

In my experience, cache has not been my friend.  Rather than being strapped for it, I’ve often found myself with just too much cache.  I’ll be pounding away at a stylesheet for twenty to thirty minutes – clueless, of course, as to why my changes are having no effect – when suddenly I smack myself in the forehead, clear my cache, and behold the mess I’ve made trying to get something, anything, to display.  Perhaps this happenstance is unique to my blindness for the obvious, but I know I’ve often found myself racing to solve a problem with a solution that is as simple as clearing the cache.

If my experience has been such, how can I say that cache is a web developer’s friend?  Well, obviously, cache speeds things up.  Sweet.  Need to solve a performance problem?  Try throwing some cache at it.  Cache increases the scalability of frameworks like Rails and Drupal.  Great.  The power of cache is not to be undermined by any foolishness on my part.  I would like to talk about another benefit to having lots of cache, though.  If you are wise, using cache might save you hours of work.  Let me relate another one of my bungles.

I’m pretty new to Drupal.  How was I to know that certain directories within sites/default/files/ were overwritten by Drupal’s own caching (O, how thick the irony!)?  I decided that I would cut out the middleman and work directly on the server.  I placed my stylesheet into sites/default/files/css/ (at this point understanding practically nothing about Drupal theming and styling) and began cracking away for two or three hours.  Naturally, my page was gorgeous.  I was proud.  Things were great.  I showed my project manager.  He gave it the go-ahead.  We went live with the page.  I backed up the server.  My PM messaged me asking what was wrong.  I said nothing.  He said, “Refresh”.  I did.  I said, “Crap.”

It was gone.

My stylesheet was niftily destroyed by Drupal’s caching mechanisms when I backed up the database.  Two or three hours of work down the drain.  My real downfall was my next move:  I hastily uploaded a scrap of the file I had on my local…AND REFRESHED MY BROSWER.  Next, a good developer friend of mine, upon hearing my plight, yawned and told me to check my  browser cache for the file.  !!  Clearly, my blindness for the obvious was in operation.  I typed about:cache into my address bar, navigated to the file, and clicked with glorious anticipation…only to be let down by a string of hexadecimal.  The only thing you can access that way is the fingerprint of the file.  I immediately ran the following:
sudo updatedb
locate cache

(because I usually don’t think where Ubuntu would logically store things and rely on locate far too much) and navigated to my .cache folder only to be dismayed as I opened a hexadecimal fingerprint of the file I needed.

Alas, it was time to bring Google to bear on the situation.  Since Google Chrome and Chromium are my browsers of choice I did a search on: view chrome cache which lead to this little guy from NirSoft. What a fantastic solution?! ChromeCacheView.exe allows you to get your cache out of the bank by saving files from your Google Chrome or Chromium cache. I was saved! Well, at least that’s what I thought until I opened the stylesheet and realized I had overwritten my cache when I uploaded that scrap of the file! That’s when I got a terrible sinking feeling in my gut. I would have to redo all of my work.

The rework aside, I learned a valuable lesson. When your file disappears off the server, pull your local version of the file from your cache before uploading a new file to the server and letting the server overwrite your browser’s cache. You might just get lucky by accessing the most recent version of the file and saving yourself some extra time.

If you’ve been following along closely, you’ll have noticed that I mentioned both Ubuntu and a .exe file. Well, there’s a solution for that! Wine is a cool way to run Windows programs on Ubuntu (among other operating systems). I used ChromeCacheView.exe without a hitch on Ubuntu 10.04 with the latest version of Wine. You can see the entry I made at the Wine AppDB here. Here’s another tip if you’re using Ubuntu+Wine: your cache folder is most likely in one of these two places: ~/.cache/google-chrome/Cache

You’ll have to change the cache folder in ChromeCacheView.

Happy Cache Raiding!

Colin Foley

Colin Foley

Colin's programming career began in high school where he began to learn the ins and outs of the Java language. While attending Lehigh University, he focused his efforts on web development. Ever since then, the majority of his work experience has been developing websites with PHP, MySQL, Adobe ColdFusion, J2EE, HTML and CSS.

Leave a Reply

Your email address will not be published. Required fields are marked *



Recent Posts