How to cache partial content with PHP

I recently come to a problem where i needed a cache part of the result to speed up the execution of statistics on a client page. The solution I was looking for was simple, I just needed something to partially cache the output and save it to static html-files. Looking around I found many different solution, but they were either to big (depending on a template system in use) or relied on Memcache or APC for controlling the output.

Instead I started looking at the built in function for output-buffering in PHP, which provides a simple way to store everything otherwise written to the client. When I couldn't find any existing solution which met my needs, I decided to create my own Partial PHP Cache system. The key features are:

  • Simple to install, single class
  • Works with minimal interruption with existing functionality
  • Caches partial content into static html-files

Example implementation:

<?php
$cache = new PartialCache("statistics", $userid);
if ($cache->start()):
// Database query....
?>
<h1>Result</h1>
 
<?php echo $result;<?>
 
<?php
endif;
$cache->render();
?>

Everything between start and render will be cached, when rendering the result the content will either be read from the cache or if cache is missing the output will be saved for next time, when the same userid visits the page (could be changed to IP, country etc. to suit your needs). In my example the cache will also be refreshed every day based on the file age.

Posted at 15.24 on 6.13.10 | no comments | Filed Under: Programming | read on

Next name for a Volvo model: Optimus Prime

The original Optimus Prime transforms into a cab over truck. The truck's cab transforms into the robot mode of Prime himself, with vast strength and armed with a laser rifle.

Optimus PrimePicture by RoninKengo

Providing a Volvo with a laser rifle might be ethically questionable, but run-time transformation, that's a feature worth exploring, isn't it? Volvo Cars, and many car manufacturers with them, are increasingly dependent on software to meet customer demands, improve safety, and reduce carbon emissions. Many employ software product lines to derive similar products from a core set of components. For example, despite what you might think, each new Volvo car ordered today is manufactured according to your preferences. As Jan Bosch explains in his book "Design and use of software architectures: adopting and evolving a product-line approach" being able to manage variations is perhaps the single most important aspect in such software product line architectures. However, with the ever growing complexity of requirements, variation patterns used in the automotive industry today are insufficient. We need to look further (perhaps to Optimus Prime?) to find suitable solutions.

In our thesis, we argue for a run-time variation mechanism as one way of meeting the increased configuration demands. Using an adaptation of the publisher-subscriber pattern, we demonstrate in a prototype compliant to AUTOSAR (a growing industry standard), how variations in software can be managed in run-time, i.e while the car is running. Moreover, we provide a number of technical insights but I won't go through all here. You're better off downloading our article and reading the complete story there.

All in all, it has been a fun and challenging (and at times boring) work to do, but we're pretty proud and satisfied with the result. While there is some more research to be done before Volvo names their next car model to Optimus Prime, I think it's safe to say that it did provide some useful inspiration during our work.

Psst! The report has diagrams and tables too

Posted at 11.02 on 6.2.10 | no comments | Filed Under: Software architecture | read on

About

Quandoo is a stamp used by Marcus Ljungblad and Emil Janitzek, two students from the Software Engineering and Management programme at the IT-University of Gothenburg. Over three years Quandoo has been involved with various projects, spanning a broad area of technologies:

  • Programming Java supervision
  • A BitTorrent client in Erlang
  • Erlang supervision
  • Mars Explorer - a self-navigating robot
  • Non-software organisations contributing to the open-source community - a change management perspective
  • Test and Verification supervision
  • Thesis: "Exploring variation mechanisms in the automotive industry: a case study"

Quandoo originally started out as the name of a project group at the IT-university. Its previous members included Jesper Lindberg, Yao Monan, Wang Zhe, Magnus Klaar, Emelie Tyvik, and Rob Bruinsma.