Visit SlideShowPro.net  Community Forums
SlideShowPro Support Wiki
  
SlideShowPro Director

Cache methods

Even with the caching that Director does on the server, API methods should be cached using the DirectorPHP class to optimize performance.

How important is this? Numbers don't lie, so here is a test on a local setup running Apache bench with 1000 requests:

Caching disabled: Requests per second: 8.27 [#/sec] (mean)
Caching enabled: Requests per second: 263.18 [#/sec] (mean)

Considering it is only one line of code to add, you should really use this once you are finished setting up your gallery. You only need to familiarize yourself with one method, set:

set(key, expires)

Instructs the DirectorPHP class to cache this request. The required key parameter is a unique string to cache the response with, and should be different for each page you set up. The expires parameter is optional and defaults to '+1 hour', meaning the cache will expire in one hour. Other examples include '+5 minutes', '+1 day', etc.

In most cases, Director will be able to ping back to your API application and clear the cache. So, the expires parameter is more of a fallback than anything.

<?php

   include('classes/DirectorPHP.php');
   $director = new Director('your-api-key', 'your-api-path');

   $director->cache->set('example-cache');

   $format = array(
      'name' => 'thumb', 
      'width' => '100', 
      'height' => '100', 
      'crop' => 1, 
      'quality' => 75, 
      'sharpening' => 1
   );

   $director->format->add($format);
   $recent = $director->content->all(10);

   foreach($recent as $content) {
      echo '<img src="' . $content->thumb->url . '" />';
   }

?>

disable()

Instructs the DirectorPHP class to disable the cache for the next API call. The cache is automatically re-enabled for the following call.

<?php

   include('classes/DirectorPHP.php');
   $director = new Director('your-api-key', 'your-api-path');

   $director->cache->set('example-cache');

   # This call is cached
   $recent = $director->albums->list()

   $director->cache->disable();
   # This call is not cached
   $recent = $director->content->all(10);

?>

Page last modified by bdaily on July 11, 2008, at 08:32 PM
© 2011 SlideShowPro. All Rights Reserved.