Today I taught myself how to use Zend_Cache and implemented it within 20 minutes. It’s super easy and very effective. Take a look at the code sample below and you’ll be up and running in no time.
Step 1: Setup the Cache
$frontendOptions = array(
‘lifetime’ => 180, // Cache for 3 minutes
‘automatic_serialization’ => true
$backendOptions = array(‘cache_dir’ => dirname(__FILE__) . ‘/cache/’);
$cache = Zend_Cache::factory(
Step 2: Use the Cache
$data = null;
if(!$data = $cache->load(‘data’))
$service = new Service(API_KEY);
$result = $service->generateReport();
$data = $service->getReport();
The page load time went from about 9 seconds to 0.5 seconds! 18x faster and it only took a few lines of code. Awesome.
My main motivation for caching the data ($data in the code example) was actually to reduce the load on the web service which provides the data. We have a good relationship with the company providing the service but there’s a good chance they would become annoyed if we hammered their system to get the exact same data over and over. The load time improvement was a good side effect, though!
For more information on Zend_Cache which comes with the Zend Framework, check out the reference guide and API documentation.
Kara and I just returned from a seven-day trip to Puerto Vallarta, Mexico. We stayed at Royal Decameron Costa Flamingos all-inclusive resort which had fantastic scenery and was reasonably priced at $1700 for the week including all meals, unlimited drinks, taxis to and from the airport, and airfare.
The best part of most vacations is being able to relax and we sure did. Most days went like so: wake up at 10:00; eat breakfast; get in the ocean until 12:00; swim until 1:00; eat lunch; swim some more; get ready for dinner and eat it; take pictures and enjoy one of five bars. Awesome.
We did venture out of the resort once on foot in an effort to go downtown but were too frightened by our surroundings so we promptly turned around after walking for about 10 minutes. After that we decided to book a snorkeling tour instead which was great because the taxi picked us up right in front of the resort.
My only complaints were lack of air conditioning everywhere except the rooms and mediocre food. But Kara and I quickly found a work-around by making reservations at the on-site Piccolo restaurant which was enclosed (cooler but not air conditioned) and had food at least three times better than the other restaurants we tried so therefore we ate there three out of the seven nights. Even so, a quick trip to Applebee’s when we returned was in order to get some decent dessert. For some reason only flan and nasty, hard cookies were supplied.
On-site Restaurant Rating (best to worst):
- Piccolo (Italian)
- Rodizio (Brazilian Grill)
- Wok (Thai)
- Buffets (each night the theme changes)
- Mexicano (Mexican)
- JapJap (Japanese)
The bars were numerous (5) and inviting. My favorite drink was the mango margarita followed closely by what they called a frozen brown cow which was simply Kahlua and milk.
Enough rambling. Enjoy the pictures!