Author: chabotc
Date: Tue Jan 27 12:34:18 2009
New Revision: 738072

URL: http://svn.apache.org/viewvc?rev=738072&view=rev
Log:
Added a feature cache specific config, this allows you to use a local cache for 
features (like apc or file) and a shared cache like memcache for remote content

Modified:
    incubator/shindig/trunk/php/.htaccess
    incubator/shindig/trunk/php/config/container.php
    incubator/shindig/trunk/php/src/gadgets/GadgetContext.php
    incubator/shindig/trunk/php/src/gadgets/GadgetServer.php
    incubator/shindig/trunk/php/src/gadgets/JsLibrary.php
    incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
    incubator/shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php
    incubator/shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php

Modified: incubator/shindig/trunk/php/.htaccess
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/.htaccess?rev=738072&r1=738071&r2=738072&view=diff
==============================================================================
--- incubator/shindig/trunk/php/.htaccess (original)
+++ incubator/shindig/trunk/php/.htaccess Tue Jan 27 12:34:18 2009
@@ -5,4 +5,6 @@
         # NOTE: If you added a web_prefix to config, add it here too, e.g.:
         #RewriteRule (.*) /shindig/php/index.php [L]
         RewriteRule (.*) index.php [L]
+       # for OAuth signatures to work for POSTed data, 
always_populate_raw_data needs to be turned on
+       php_flag always_populate_raw_post_data On
 </IfModule>

Modified: incubator/shindig/trunk/php/config/container.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/config/container.php?rev=738072&r1=738071&r2=738072&view=diff
==============================================================================
--- incubator/shindig/trunk/php/config/container.php (original)
+++ incubator/shindig/trunk/php/config/container.php Tue Jan 27 12:34:18 2009
@@ -20,10 +20,10 @@
 
 /**
  * The default configuration settings
- * 
+ *
  * Put any site specific configuration in a config/local.php file, this way
  * your configuration won't be lost when upgrading shindig.
- * 
+ *
  * in local.php you only have to specificy the fields you want to overwrite
  * with other values, for example on a production system you would probably 
have:
  * $shindigConfig = array(
@@ -40,93 +40,97 @@
  *     'xrds_location' => 'http://www.mycontainer.com/xrds',
  *  'check_file_exists' => false
  * );
- *  
+ *
  */
 $shindigConfig = array(
   // Show debug backtrace's. Disable this on a production site
-  'debug' => true, 
+  'debug' => true,
   // do real file_exist checks? Turning this off can be a big performance gain 
on prod servers but also risky & less verbose errors
-  'check_file_exists' => true, 
-  
+  'check_file_exists' => true,
+
   // Allow plain text security tokens, this is only here to allow the sample 
files to work. Disable on a production site
-  'allow_plaintext_token' => true, 
+  'allow_plaintext_token' => true,
   // Compress the inlined javascript, saves upto 50% of the document size
-  'compress_javascript' => true, 
-  
+  'compress_javascript' => true,
+
   // The URL Prefix under which shindig lives ie if you have 
http://myhost.com/shindig/php set web_prefix to /shindig/php
   'web_prefix' => '',
   // If you changed the web prefix, add the prefix to these too
-  'default_js_prefix' => '/gadgets/js/', 
-  'default_iframe_prefix' => '/gadgets/ifr?', 
-    
-  // The X-XRDS-Location value for your implementing container, if any, see 
http://code.google.com/p/partuza/source/browse/trunk/Library/XRDS.php for an 
example
-  'xrds_location' => '', 
+  'default_js_prefix' => '/gadgets/js/',
+  'default_iframe_prefix' => '/gadgets/ifr?',
+
+  // The X-XRDS-Location value for your implementing container, see 
http://code.google.com/p/partuza/source/browse/trunk/Library/XRDS.php for an 
example
+  'xrds_location' => '',
 
   // Allow anonymous (READ) access to the profile information? (aka REST and 
JSON-RPC interfaces)
   // setting this to false means you have to be authenticated through OAuth to 
read the data
-  'allow_anonymous_token' => true, 
-  
+  'allow_anonymous_token' => true,
+
   // The encryption keys for encrypting the security token, and the expiration 
of it. Make sure these match the keys used in your container/site
-  'token_cipher_key' => 'INSECURE_DEFAULT_KEY', 
+  'token_cipher_key' => 'INSECURE_DEFAULT_KEY',
   'token_hmac_key' => 'INSECURE_DEFAULT_KEY',
-  'token_max_age' => 60 * 60, 
-  
+  'token_max_age' => 60 * 60,
+
   // Ability to customize the style thats injected into the gadget document. 
Don't forget to put the link/etc colors in shindig/config/container.js too!
-  'gadget_css' => 'body,td,div,span,p{font-family:arial,sans-serif;} a 
{color:#0000cc;}a:visited {color:#551a8b;}a:active {color:#ff0000;}body{margin: 
0px;padding: 0px;background-color:white;}', 
-  
+  'gadget_css' => 'body,td,div,span,p{font-family:arial,sans-serif;} a 
{color:#0000cc;}a:visited {color:#551a8b;}a:active {color:#ff0000;}body{margin: 
0px;padding: 0px;background-color:white;}',
+
   // P3P privacy policy to use for the iframe document
-  'P3P' => 'CP="CAO PSA OUR"', 
-  
+  'P3P' => 'CP="CAO PSA OUR"',
+
   // The locations of the various required components on disk. If you did a 
normal svn checkout there's no need to change these
-  'base_path' => realpath(dirname(__FILE__) . '/..') . '/', 
-  'features_path' => realpath(dirname(__FILE__) . '/../../features') . '/', 
-  'container_path' => realpath(dirname(__FILE__) . '/../../config') . '/', 
-  'javascript_path' => realpath(dirname(__FILE__) . '/../../javascript') . 
'/', 
-  
-  // The OAuth SSL certificates to use, and the pass phrase for the private 
key  
-  'private_key_file' => realpath(dirname(__FILE__) . '/../certs') . 
'/private.key', 
-  'public_key_file' => realpath(dirname(__FILE__) . '/../certs') . 
'/public.crt', 
-  'private_key_phrase' => 'partuza', 
+  'base_path' => realpath(dirname(__FILE__) . '/..') . '/',
+  'features_path' => realpath(dirname(__FILE__) . '/../../features') . '/',
+  'container_path' => realpath(dirname(__FILE__) . '/../../config') . '/',
+  'javascript_path' => realpath(dirname(__FILE__) . '/../../javascript') . '/',
+
+  // The OAuth SSL certificates to use, and the pass phrase for the private key
+  'private_key_file' => realpath(dirname(__FILE__) . '/../certs') . 
'/private.key',
+  'public_key_file' => realpath(dirname(__FILE__) . '/../certs') . 
'/public.crt',
+  'private_key_phrase' => 'partuza',
 
   // the path to the json db file, used only if your using the 
JsonDbOpensocialService example/demo service
-  'jsondb_path' => realpath(dirname(__FILE__) . 
'/../../javascript/sampledata') . '/canonicaldb.json', 
-  
+  'jsondb_path' => realpath(dirname(__FILE__) . 
'/../../javascript/sampledata') . '/canonicaldb.json',
+
   // Force these libraries to be external (included through <script src="..."> 
tags), this way they could be cached by the browser
-  'focedJsLibs' => '', 
+  'focedJsLibs' => '',
 
   // Configurable classes. Change these to the class name to use, and make 
sure the auto-loader can find them
-  'blacklist_class' => 'BasicGadgetBlacklist', 
+  'blacklist_class' => 'BasicGadgetBlacklist',
   'remote_content' => 'BasicRemoteContent',
-  'security_token_signer' => 'BasicSecurityTokenDecoder', 
+  'security_token_signer' => 'BasicSecurityTokenDecoder',
   'security_token' => 'BasicSecurityToken',
-  'oauth_lookup_service' => 'BasicOAuthLookupService', 
-  
-  // Caching back-end to use. Shindig ships with CacheFile and CacheMemcache 
out of the box
-  'data_cache' => 'CacheFile', 
+  'oauth_lookup_service' => 'BasicOAuthLookupService',
+
+  // Caching back-end's to use. Shindig ships with CacheFile, CacheApc and 
CacheMemcache support
+  // The data cache is primarily used for remote content (proxied files, 
gadget spec, etc)
+  // and the feature_cache is used to cache the parsed features xml structure 
and javascript
+  // On a production system you probably want to use CacheApc for features, 
and CacheMemcache for the data cache
+  'data_cache' => 'CacheFile',
+  'feature_cache' => 'CacheFile',
 
   // RESTful API data service classes to use
   // See http://code.google.com/p/partuza/source/browse/#svn/trunk/Shindig for 
a MySql powered example
-  'person_service' => 'JsonDbOpensocialService', 
+  'person_service' => 'JsonDbOpensocialService',
   'activity_service' => 'JsonDbOpensocialService',
-  'app_data_service' => 'JsonDbOpensocialService', 
-  'messages_service' => 'JsonDbOpensocialService', 
+  'app_data_service' => 'JsonDbOpensocialService',
+  'messages_service' => 'JsonDbOpensocialService',
 
-  // Also scan these directories when looking for <Class>.php files. You can 
include multiple paths by seperating them with a , 
-  'extension_class_paths' => '', 
+  // Also scan these directories when looking for <Class>.php files. You can 
include multiple paths by seperating them with a ,
+  'extension_class_paths' => '',
 
   'userpref_param_prefix' => 'up_',
-  'libs_param_name' => 'libs', 
+  'libs_param_name' => 'libs',
 
   // If you use CacheMemcache as caching backend, change these to the memcache 
server settings
   'cache_host' => 'localhost',
   'cache_port' => 11211,
-  'cache_time' => 24 * 60 * 60, 
+  'cache_time' => 24 * 60 * 60,
   // If you use CacheFile as caching backend, this is the directory where it 
stores the temporary files
-  'cache_root' => '/tmp/shindig', 
+  'cache_root' => '/tmp/shindig',
 
   // connection timeout setting for all curl requests, set this time something 
low if you want errors reported
   // quicker to the end user, and high (between 10 and 20) if your on a slow 
connection
-  'curl_connection_timeout' => '10', 
+  'curl_connection_timeout' => '10',
 
   // If your development server is behind a proxy, enter the proxy details 
here in 'proxy.host.com:port' format.
   'proxy' => ''

Modified: incubator/shindig/trunk/php/src/gadgets/GadgetContext.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetContext.php?rev=738072&r1=738071&r2=738072&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetContext.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetContext.php Tue Jan 27 
12:34:18 2009
@@ -46,7 +46,7 @@
   public function __construct($renderingContext) {
     // Rendering context is set by the calling event handler (either GADGET or 
CONTAINER)
     $this->setRenderingContext($renderingContext);
-    
+
     // Request variables
     $this->setIgnoreCache($this->getIgnoreCacheParam());
     $this->setForcedJsLibs($this->getFocedJsLibsParam());
@@ -133,17 +133,14 @@
     return new $remoteContent();
   }
 
-  private function instanceCache() {
-    $dataCache = Config::get('data_cache');
-    return new $dataCache();
-  }
-
   private function instanceRegistry() {
     // Profiling showed 40% of the processing time was spend in the feature 
registry
     // So by caching this and making it a one time initialization, we almost 
double the performance
-    if (! ($registry = 
$this->getCache()->get(md5(Config::get('features_path'))))) {
+    $featureCache = Config::get('feature_cache');
+    $featureCache = new $featureCache();
+    if (! ($registry = $featureCache->get(md5(Config::get('features_path'))))) 
{
       $registry = new GadgetFeatureRegistry(Config::get('features_path'));
-      $this->getCache()->set(md5(Config::get('features_path')), $registry);
+      $featureCache->set(md5(Config::get('features_path')), $registry);
     }
     return $registry;
   }
@@ -170,13 +167,6 @@
     return $this->containerConfig;
   }
 
-  public function getCache() {
-    if ($this->cache == null) {
-      $this->setCache($this->instanceCache());
-    }
-    return $this->cache;
-  }
-
   public function getGadgetId() {
     if ($this->gadgetId == null) {
       $this->setGadgetId($this->instanceGadgetId($this->getUrl(), 
$this->getModuleId()));

Modified: incubator/shindig/trunk/php/src/gadgets/GadgetServer.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetServer.php?rev=738072&r1=738071&r2=738072&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetServer.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetServer.php Tue Jan 27 
12:34:18 2009
@@ -23,6 +23,7 @@
   public function processGadget($context) {
     $gadget = $this->specLoad($context);
     $this->featuresLoad($gadget, $context);
+    $this->substitute($gadget, $context);
     return $gadget;
   }
 
@@ -45,8 +46,7 @@
     $localeSpec = $this->localeSpec($gadget, $locale); // en-US
     $language_allSpec = $this->localeSpec($gadget, new 
Locale($locale->getLanguage(), "all")); // en-all
     $all_allSpec = $this->localeSpec($gadget, new Locale("all", "all")); // 
all-all
-    $messagesArray = $this->getMessagesArrayForSpecs($context, 
array($localeSpec, $language_allSpec, 
-        $all_allSpec));
+    $messagesArray = $this->getMessagesArrayForSpecs($context, 
array($localeSpec, $language_allSpec, $all_allSpec));
     if (count($messagesArray) == 0) {
       return null;
     }
@@ -113,7 +113,7 @@
     return null;
   }
 
-  private function featuresLoad(Gadget $gadget, $context) {
+  private function substitute(Gadget $gadget, $context) {
     //NOTE i've been a bit liberal here with folding code into this function, 
while it did get a bit long, the many include()'s are slowing us down
     // get the message bundle for this gadget
     $bundle = $this->getBundle($context, $gadget);
@@ -138,7 +138,7 @@
     $substitutor->addSubstitution('BIDI', "DIR", $rtl ? "rtl" : "ltr");
     $substitutor->addSubstitution('BIDI', "REVERSE_DIR", $rtl ? "ltr" : "rtl");
     foreach ($gadget->userPrefs as $pref) {
-      if (!empty($pref->displayName)) {
+      if (! empty($pref->displayName)) {
         $pref->displayName = 
$gadget->getSubstitutions()->substitute($pref->displayName);
       }
       if (is_array($pref->enumValues) && count($pref->enumValues)) {
@@ -161,6 +161,9 @@
       $substitutor->addSubstitution('UP', $name, $value);
     }
     $this->substitutePreloads($gadget, $substitutor);
+  }
+
+  function featuresLoad(Gadget $gadget, $context) {
     // Process required / desired features
     $requires = $gadget->getRequires();
     $needed = array();

Modified: incubator/shindig/trunk/php/src/gadgets/JsLibrary.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/JsLibrary.php?rev=738072&r1=738071&r2=738072&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/JsLibrary.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/JsLibrary.php Tue Jan 27 12:34:18 
2009
@@ -38,11 +38,11 @@
   public function getContent() {
     if (! $this->loaded && $this->type == 'FILE') {
       if (Config::get('compress_javascript')) {
-        $dataCache = Config::get('data_cache');
-        $dataCache = new $dataCache();
-        if (! ($content = $dataCache->get(md5($this->content)))) {
+        $featureCache = Config::get('feature_cache');
+        $featureCache = new $featureCache();
+        if (! ($content = $featureCache->get(md5($this->content)))) {
           $content = JsMin::minify(JsLibrary::loadData($this->content, 
$this->type));
-          $dataCache->set(md5($this->content), $content);
+          $featureCache->set(md5($this->content), $content);
           $this->content = $content;
         } else {
           $this->content = $content;

Modified: 
incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php?rev=738072&r1=738071&r2=738072&view=diff
==============================================================================
--- 
incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php 
(original)
+++ 
incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php 
Tue Jan 27 12:34:18 2009
@@ -19,7 +19,7 @@
  */
 
 class BasicGadgetOAuthTokenStore extends GadgetOAuthTokenStore {
-  
+
   /** default location for consumer keys and secrets */
   private $OAUTH_CONFIG = "../config/oauth.json";
   private $CONSUMER_SECRET_KEY = "consumer_secret";
@@ -96,5 +96,4 @@
     $kas = new ConsumerKeyAndSecret($consumerKey, $consumerSecret, $keyType);
     $this->storeConsumerKeyAndSecret($gadgetUri, $serviceName, $kas);
   }
-
 }

Modified: 
incubator/shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php?rev=738072&r1=738071&r2=738072&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php 
(original)
+++ incubator/shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php 
Tue Jan 27 12:34:18 2009
@@ -22,8 +22,9 @@
  * Basic implementation of a gadget spec factory.
  */
 class BasicGadgetSpecFactory implements GadgetSpecFactory {
-  
+
   private $fetcher;
+  private $cache;
 
   public function __construct($fetcher) {
     $this->fetcher = $fetcher;
@@ -37,10 +38,7 @@
    * Retrieves a gadget specification from the cache or from the Internet.
    */
   public function getGadgetSpecUri($url, $ignoreCache) {
-    if ($ignoreCache) {
-      return $this->fetchFromWeb($url, true);
-    }
-    return $this->fetchFromWeb($url, false);
+    return $this->fetchFromWeb($url, $ignoreCache);
   }
 
   /**

Modified: 
incubator/shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php?rev=738072&r1=738071&r2=738072&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php 
(original)
+++ incubator/shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php 
Tue Jan 27 12:34:18 2009
@@ -166,7 +166,7 @@
       $content .= sprintf($externFmt, Config::get('default_js_prefix') . 
$this->getJsUrl($libs, $gadget) . "&container=" . $context->getContainer()) . 
"\n";
     }
     $content .= "<script>\n";
-    
+
     if (! empty($forcedLibs)) {
       // if some of the feature libraries are externalized (through a browser 
cachable <script src="/gadgets/js/opensocial-0.7:settitle.js">
       // type url), then we don't want to include dependencies twice, so find 
the complete features chain, so we can skip over those
@@ -301,7 +301,8 @@
         $buf .= $lib;
       }
     }
-    $cache = $this->context->getCache();
+    $cache = Config::get('feature_cache');
+    $cache = new $cache();
     if (($md5 = $cache->get(md5('getJsUrlMD5'))) === false) {
       $registry = $this->context->getRegistry();
       $features = $registry->getAllFeatures();
@@ -339,7 +340,7 @@
         }
       }
     }
-    
+
     // Add gadgets.util support. This is calculated dynamically based on 
request inputs.
     // See 
java/org/apache/shindig/gadgets/render/RenderingContentRewriter.java for 
reference.
     $requires = array();
@@ -347,7 +348,7 @@
       $requires[$feature->name] = new EmptyClass();
     }
     $gadgetConfig['core.util'] = $requires;
-    
+
     return "gadgets.config.init(" . json_encode($gadgetConfig) . ");\n";
   }
 
@@ -417,7 +418,7 @@
         $responses = $brc->multiFetch($unsignedRequests, $unsignedContexts);
         foreach ($responses as $response) {
           $resp[$response->getUrl()] = array(
-              'body' => $response->getResponseContent(), 
+              'body' => $response->getResponseContent(),
               'rc' => $response->getHttpCode());
         }
       } catch (Exception $e) {
@@ -430,7 +431,7 @@
         $responses = $fetcher->multiFetchRequest($signedRequests);
         foreach ($responses as $response) {
           $resp[$response->getNotSignedUrl()] = array(
-              'body' => $response->getResponseContent(), 
+              'body' => $response->getResponseContent(),
               'rc' => $response->getHttpCode());
         }
       } catch (Exception $e) {


Reply via email to