Chapter. Non-object oriented programming patterns
Fallingwater in its setting embodies a powerful ideal – that people today can learn to live in harmony with nature.
—Edgar Kaufmann, Jr.
The pattern I want to discuss goes by many names: “Funky Caching”, “404 trick”, “Smarter Caching”, “Rasmus’s Trick”, etc. It was introduced by Stig Bakken, first presented by PHP creator Rasmus Lerdorf in 2002.
The idea is to trap HTTP 404 Not Found
errors in the web server and launch a server-side script that generates the missing file as a static resource into the requested web server path, and returns the page to the user with an HTTP 200
. Future requests will then go directly to the resource bypassing the server-side code entirely.
My title while at Tagged was “software architect.” And I have a “radical” idea that maybe titles are that way because they mean something. Meaning that if I’m hired as a software architect then I should think like an architect and find my inspiration from architecture.
Building #1: Fallingwater
Nestled along a creek in the woods of southwestern Pennsylvania is a house that’s angular features are cantilevered 40 feet above a waterfall. This was the summer home of the Kaufmann family, owners of a Pittsburgh department store. (I remember that department store well because I whiled away the time my mom spent shopping there, next-door in a neighboring newsstand reading issues of MAD magazine and Cracked.)
When I was a kid, my dad took us to visit the place, and I became one of millions of visitors to Fallingwater, a home that on its creation was hailed by TIME magazine and became known as the quintessential example of the organic architecture of architect Frank Lloyd Wright.
Why is Fallingwater, a summer home for a Pittsburgh family, so obviously beautiful that hundreds of thousands make the trek (50 miles from the nearest city) each year? Why was it was voted “best all-time work of American architecture” in 1991 by the American Institute of Architects? Why are pictures of a simple summer home in the Pennsylvania woods instantly recognizable as any natural wonder?
Maybe it’d be enlightening to consider how Frank Lloyd Wright built it. Before he started, he commissioned a survey to of the entire topography around the waterfall and had them include all trees and boulders. He then came up with an idea of a cantilevered house that would stretch in a manner that would look like it floated in air above the waterfall.
Perhaps it is because details such as these:
- A staircase connects the house directly to the stream below. The stream and waterfall, though not seen, can be heard in all parts of the house.
- Windows wrap around the entire building such that the tungsten lighting of the interior would complement the fall foliage and the house and greenery would merge optically throughout the house
- This glass was often caulked directly to each other and to the steel frame or stone walls to further symbolize the lack of barriers between the construction and the surrounding nature.
- The driveway trellis had a semi-circular cutaway to accommodate an existing tree.
- The stone floor in the living room, quarried from local rocks, is actually built around a boulder undisturbed from its original position in the site.
From details like that to the whole view taken in at once, one gets a feeling that, in spite of the sharp horizontal and vertical lines of the building, the whole lives in harmony with its environment “instead of lording above it[it] in an isolated spot as a man-made imposition.”
Frank Lloyd Wright designed on the principles of: “organic, democratic, plasticity, continuity.” We can see how this example holds true to those values.
Could this building have been built anywhere else?
(This discussion will be continued in Chapter X.)
…
Why is Funky Caching trick so prevalent in the PHP world?
If you look at Funky Caching, it doesn’t need PHP to implement it. This begs the question as to why it first appeared in the PHP world? Why is this obscure design pattern so ubiquitous in the PHP world? In fact PHP developers use it practically every day, the instant you type http://www.php.net/strstr
in your browser to figure out the order of the needle in the haystack. Most requests are statically served, but when a comment is updated or documentation is updated, the page is simply wiped. The next request re-generates the page.
A cynic would say because PHP is so slow to execute it needs solutions like this to perform well. The problem with this argument is that no single web language outperforms the fastest static servers out there, or even come close to the slow ones. There is no web programming language in existence that wouldn’t benefit from this trick.
But there is truth to the cynic’s statement. The PHP world may have discovered this first because it trades off speed of execution with speed and ease of development—that is fundamental to its design. In fact, all dynamically typed scripting languages make this tradeoff.
The ubiquity of this trick in the PHP world is because it—like Frank Lloyd Wright’s Fallingwater—lives in harmony with its environment. The environment is an Apache web server, persistent data store in the form of a relational database, and the demands of large-scale consumer-facing web. Would this solution exist without an Error Document handler built into Apache? Would this solution exist if we didn’t persist content on a (relatively) slow data store like a database? Would this solution exist if the consumer didn’t demand millisecond response time for dynamic content?
Funky Caching in the PHP world lives in harmony with that environment. It lives in harmony with PHP itself.