Java Reference
In-Depth Information
I decided that my biggest mistake was making the trip in the first place.
Sometimes, the best antidote for a bad trip is not to go in the first place . Poor-
performing Java applications can make an incredible number of needless
communication trips. Simply caching posts as we retrieve them will help us
tremendously. Next up, we'll look at ways we can apply caching solutions to
our problem.
5.3.1
Solution 1: Use a hardware cache
The first part of our refactored solution, called a caching proxy , deals with the
static content and is completely independent of Java. This solution is a piece of
inexpensive hardware placed between the web server and the clients, as shown
in figure 5.2 on page 112. Because most of the HTTP requests are for images,
they can be serviced without even consulting the server.
For taxed HTTP servers, this solution can make a tremendous difference.
Each graphic, animation, or sound is retrieved independently. Good browsers
optimize by grouping these requests in blocks of four, but caching the con-
tent in a proxy can insulate a majority of the requests from ever reaching a
web server.
5.3.2
Solution 2: Cache commands
In general, a cache is simply a rapidly accessible place to store data that is
expensive to retrieve. PC s generally have hardware caches on video cards so
that the video processors have immediate access to video data. Most operating
systems have disk caches for storing frequently accessed disk records (which is
one of the reasons you have to shut down the Windows operating system
instead of just turning it off). The data in these examples is fairly fluid, so we
should be able to come up with a scheme for caching the commands that fetch
our dynamic data.
In this example, we'll build a command cache. For simplicity, our example
will build a hash table into our command layer. That way, our controllers
won't need to change at all. In practice, it may be far more cost effective to
build a single, systemwide command cache. Many vendors are already working
on these types of technologies.
Instead of creating a new command from the class object each time, the
controller will ask the cache manager for a command. If a command is in the
cache, we'll return it to the requesting instance. In this case, there's no need
to initialize or execute the command, because the get attributes are already
populated. If the command isn't in the cache, the cache manager will create a
Search WWH ::




Custom Search