Cached json (or xml) view with CakePHP

While implementing caching for view as descriped in the cookbook i stumbled upon some glitches:

First I found out the best way to avoid problems with routing urls beeing not cached - especially when using Router::mapResources() - is to enable the caching per action in the controller like this:

function view($id = null) {
$this->cacheAction = "10 minutes";
// more stuff
}

The next problem was that cached views don't retain document mime type (xml, json, etc.). The first request works correctly (uncached request), but the second request will come back as text/html. You can find a more detailed description of the problem here.

I got an advice to enable callbacks for my views but that slows down and defeats the purpose of the cache. My approach now is to use a layout like this:

PHP:
  1. <cake:nocache><?php
  2. configure::write('debug',0); // surpress all debug output on json views
  3. header('Content-type: text/x-json');
  4. ?></cake:nocache><?php echo $content_for_layout; ?>

With the header('Content-type: text/x-json'); embedded in the nocache tags, it works fast and returns the correct mime type.

  • Development-Server XDebug enabled, APC enabled, View cache disabled:
    Requests per second: 1.64 [#/sec]
  • Development-Server XDebug enabled, APC enabled, View cache enabled (files):
    Requests per second: 29.04 [#/sec]
  • Development-Server XDebug disabled, APC enabled, View cache enabled (files):
    Requests per second: 95.66 [#/sec]

Further reading
8 Ways to Speed Up the Performance of CakePHP Apps.
Store View Cache in APC or Memcached.

Bookmark and Share

1 Comment

Is Chromium OS the perfect netbook OS?

After Googles launch of their own programming language "go" (which looks like a polished c++ meets pyhton) the next big thing is Googles attempt to re-think what operating systems (targeting netbooks) should be: Google Chromium OS. I don't yet follow the idea of no native apps "on the desktop". So I'm exited about Apple's plan for this netbook (or tablet-) market. As a developer I welcome every platform that allows users to access webapps in a more convenience way. And this is pretty much the best attempt for the old idea of a "network only computer": Network Computer Reloaded.

Bookmark and Share

No Comments

The Animated Google Story

A quick look back at the Google story over the last 11 years. From Stanford to Mountain View and around the world, featuring many different products, starting with BackRub (Search) up to Google Wave, StreetView and Chrome.

Bookmark and Share

No Comments

Getting Git

After reading ebooks, watching screencasts and working through some tutorials trying to get a grip on git, I found this slide that made me understand. Great! Thanks, Scott Chacon.

Another helpfull resource is: Understanding Git Conceptually

Bookmark and Share

No Comments

Social Media Revolution

Is social media a fad? Or is it the biggest shift since the Industrial Revolution?

Bookmark and Share

No Comments

EC2 Reserved Instances

With "Reserved Instances" Amazon introduced an additional pricing option for EC2 that gives an option to make a one-time payment for an instance to reserve capacity and further reduce hourly usage charges. You may look up the details at: aws.amazon.com/ec2/#pricing.

I have made a rough comparison for the classic "on demand" small instance against the new reserved instance:

On Demand Instance:
$0 + (365*24*$0,10) = $876/year = $73/month

Reserved Instance 1year:
$325 + (365*24*$0,03) = $588/year = $50/month
Saves you $288/year or $24/month.

Reserved Instance 3years:
$500 + (3*365*24*$0,03) = $1288/3years = $430/year = $36/month
Saves you 446 $/year or 37$/month.

Here's the offical FAQ on using Reserved Instances. And here's a funny but critically blog post about the "single commandline that can costs you losts of money". I think Marc Musings is right and I wish that Amazon would improve this because I had the same bad emotions with this "new API feature". It would basically a good idea to have alerts and/or limits for charges, instances and traffic.

Can't wait for reserved Instances to be available for the EU region... "in the near future" as Amazon promised... Happy emotions when spending big money with ec2-purchase-reserved-instances-offering!

UPDATE 09-08-21: New Lower Prices for Amazon EC2 Reserved Instances and I'm also happy to see that one of my EC2 instance hit the 500 days uptime mark.

Bookmark and Share

, ,

No Comments

“Waiting for root file system” caused by out dated VMware Server

I run into a strange problem when I upgraded some VMs from Debian Etch to Lenny. I'm using VMware Fusion on my MacBook Pro and VMware Server on my local Debian Server. Upgrading VMs hosted by the VMware Server ended in System boot hangs "Waiting for root file system". Upgrading nearly the same Etch VMs hosted by VMware Fusion did not fail.

According to Debians Upgrade instruction and it's "How to recover" section, the problem can be caused by new naming conventions for IDE disks.

This problem can occur when the upgrade of the kernel introduces the use of the new generation of IDE drivers. The IDE disk naming convention for the old drivers was hda, hdb, hdc, hdd. The new drivers will name the same disks respectively sda, sdb, sdc, sdd. The problem appears when the upgrade does not generate a new /boot/grub/menu.lst file to take the new naming convention into account. During the boot, Grub will pass a system root partition to the kernel that the kernel doesn't find.

This seems like to be very common reason for these "Waiting for root file system" troubles that many faces now when upgrading to Lenny. But in my case I allready had the new sda* names in the grub/menu.lst and /etc/fstab. The "solution to recover" did not work.

The virtual lenny server with the new kernel images that fails to boot was hosted by VMWare Server 1.0.3. For a nearly the same upgrade process (etch to lenny) hosted on FMWare fusion 2.0.2, I did not have these problems.

Solution: My VMWare Server 1.0.3 was out of date and had a known vmware bug that caused this error. Upgrading to the latest version (now 1.0.8) solved the problem.

Bookmark and Share

, , , , , ,

No Comments