public static function invalidateGadgetCache(GadgetContext $context) { $request = new RemoteContentRequest($context->getUrl()); $cache = Cache::createCache(Shindig_Config::get('data_cache'), 'RemoteContent'); $cacheData = $cache->get($request->toHash()); if ($cacheData) { $uris = array(); $xml = $cacheData->getResponseContent(); $parserClass = Shindig_Config::get('gadget_spec_parser'); $parser = new $parserClass(); $gadgetSpec = $parser->parse($xml, $context); if ($gadgetSpec->locales) { foreach ($gadgetSpec->locales as $locale) { if (!empty($locale['messages'])) { $uris[] = RemoteContentRequest::transformRelativeUrl($locale['messages'], $context->getUrl()); } } } if (is_array($gadgetSpec->preloads)) { foreach ($gadgetSpec->preloads as $preload) { if (!empty($preload['href'])) { $uris[] = RemoteContentRequest::transformRelativeUrl($preload['href'], $context->getUrl()); } } } if (is_array($gadgetSpec->templatesRequireLibraries)) { foreach ($gadgetSpec->templatesRequireLibraries as $libraryUrl) { $uris[] = RemoteContentRequest::transformRelativeUrl($locale['messages'], $context->getUrl()); } } $uris[] = $request->getUrl(); self::invalidateRemoteContents($uris); } }
/** * generates the library string (core:caja:etc.js) including a checksum of all the * javascript content (?v=<md5 of js>) for cache busting * * @param array $features * @param Gadget $gadget * @return string the list of libraries in core:caja:etc.js?v=checksum> format */ protected function getJsUrl($features) { if (!is_array($features) || !count($features)) { return 'null'; } $registry = $this->context->getRegistry(); // Given the JsServlet automatically expends the js library, we just need // to include the "leaf" nodes of the features. $ret = $features; foreach ($features as $feature) { $depFeatures = $registry->features[$feature]['deps']; $ret = array_diff($ret, $depFeatures); } $ret = implode(':', $ret); $cache = Cache::createCache(Config::get('feature_cache'), 'FeatureCache'); if (($md5 = $cache->get(md5('getJsUrlMD5'))) === false) { $features = $registry->features; // Build a version string from the md5() checksum of all included javascript // to ensure the client always has the right version $inlineJs = ''; foreach ($features as $feature => $content) { $inlineJs .= $registry->getFeatureContent($feature, $this->context, true); } $md5 = md5($inlineJs); $cache->set(md5('getJsUrlMD5'), $md5); } $ret .= ".js?v=" . $md5; return $ret; }
/** * @param RemoteContentFetcher $basicFetcher * @param SigningFetcherFactory $signingFetcherFactory * @param SecurityTokenDecoder $signer */ public function __construct(RemoteContentFetcher $basicFetcher = null, $signingFetcherFactory = null, $signer = null) { $this->basicFetcher = $basicFetcher ? $basicFetcher : new BasicRemoteContentFetcher(); $this->signingFetcherFactory = $signingFetcherFactory; $this->signer = $signer; $this->cache = Cache::createCache(Shindig_Config::get('data_cache'), 'RemoteContent'); $this->invalidateService = new DefaultInvalidateService($this->cache); }
public function __construct() { try { $service = trim(Shindig_Config::get('invalidate_service')); if (!empty($service)) { $cache = Cache::createCache(Shindig_Config::get('data_cache'), 'RemoteContent'); $this->service = new $service($cache); } } catch (ConfigException $e) { // Do nothing. If invalidate service is not specified in the config file. // All the requests to the handler will throw not implemented exception. } }
public function __construct(Cache $cache) { $this->cache = $cache; $this->invalidationEntry = Cache::createCache(Shindig_Config::get('data_cache'), 'InvalidationEntry'); if (self::$makerCache == null) { self::$makerCache = Cache::createCache(Shindig_Config::get('data_cache'), 'MarkerCache'); $value = self::$makerCache->expiredGet('marker'); if ($value['found']) { self::$marker = $value['data']; } else { self::$marker = 0; self::$makerCache->set('marker', self::$marker); } } }
public function getFeatureContent($feature, GadgetContext $context, $isGadgetContext) { if (empty($feature)) { return ''; } if (!isset($this->features[$feature])) { throw new GadgetException("Invalid feature: " . htmlentities($feature)); } $featureName = $feature; $feature = $this->features[$feature]; $filesContext = $isGadgetContext ? 'gadgetJs' : 'containerJs'; if (!isset($feature[$filesContext])) { // no javascript specified for this context return ''; } $ret = ''; if (Config::get('compress_javascript')) { $featureCache = Cache::createCache(Config::get('feature_cache'), 'FeatureCache'); if ($featureContent = $featureCache->get(md5('features:' . $featureName . $isGadgetContext))) { return $featureContent; } } foreach ($feature[$filesContext] as $entry) { switch ($entry['type']) { case 'URL': $request = new RemoteContentRequest($entry['content']); $request->getOptions()->ignoreCache = $context->getIgnoreCache(); $response = $context->getHttpFetcher()->fetch($request); if ($response->getHttpCode() == '200') { $ret .= $response->getResponseContent() . "\n"; } break; case 'FILE': $file = $feature['basePath'] . '/' . $entry['content']; $ret .= file_get_contents($file) . "\n"; break; case 'INLINE': $ret .= $entry['content'] . "\n"; break; } } if (Config::get('compress_javascript')) { $ret = JsMin::minify($ret); $featureCache->set(md5('features:' . $featureName . $isGadgetContext), $ret); } return $ret; }
/** * Prepares the environment before running a test. */ protected function setUp() { if (!extension_loaded('memcache')) { $message = 'memcache requires the memcache extention'; throw new PHPUnit_Framework_SkippedTestSuiteError($message); } parent::setUp(); $this->time = new MockRequestTime(); try { $this->cache = Cache::createCache('CacheStorageMemcache', 'TestCache', $this->time); } catch (Exception $e) { $message = 'memcache server can not connect'; throw new PHPUnit_Framework_SkippedTestSuiteError($message); } if (!is_resource($this->cache)) { $message = 'memcache server can not connect'; throw new PHPUnit_Framework_SkippedTestSuiteError($message); } }
/** * generates the library string (core:caja:etc.js) including a checksum of all the * javascript content (?v=<md5 of js>) for cache busting * * @param string $libs * @param Gadget $gadget * @return string the list of libraries in core:caja:etc.js?v=checksum> format */ protected function getJsUrl($features) { if (!is_array($features) || !count($features)) { return 'null'; } $ret = implode(':', $features); $cache = Cache::createCache(Config::get('feature_cache'), 'FeatureCache'); if (($md5 = $cache->get(md5('getJsUrlMD5'))) === false) { $registry = $this->context->getRegistry(); $features = $registry->features; // Build a version string from the md5() checksum of all included javascript // to ensure the client always has the right version $inlineJs = ''; foreach ($features as $feature => $content) { $inlineJs .= $registry->getFeatureContent($feature, $this->context, true); } $md5 = md5($inlineJs); $cache->set(md5('getJsUrlMD5'), $md5); } $ret .= ".js?v=" . $md5; return $ret; }
private function storeConsumerInfo($gadgetUri, $serviceName, $consumerInfo) { if (!isset($consumerInfo[$this->CONSUMER_SECRET_KEY]) || !isset($consumerInfo[$this->CONSUMER_KEY_KEY]) || !isset($consumerInfo[$this->KEY_TYPE_KEY])) { throw new Exception("Invalid configuration in oauth.json"); } $consumerSecret = $consumerInfo[$this->CONSUMER_SECRET_KEY]; $consumerKey = $consumerInfo[$this->CONSUMER_KEY_KEY]; $keyTypeStr = $consumerInfo[$this->KEY_TYPE_KEY]; $keyType = 'HMAC_SYMMETRIC'; if ($keyTypeStr == "RSA_PRIVATE") { $keyType = 'RSA_PRIVATE'; $cache = Cache::createCache(Shindig_Config::get('data_cache'), 'OAuthToken'); if (($cachedRequest = $cache->get(md5("RSA_KEY_" . $serviceName))) !== false) { $consumerSecret = $cachedRequest; } else { $key = $consumerInfo[$this->CONSUMER_SECRET_KEY]; if (empty($key)) { throw new Exception("Invalid key"); } if (strpos($key, "-----BEGIN") === false) { $strip_this = array(" ", "\n", "\r"); //removes breaklines and trim. $rsa_private_key = trim(str_replace($strip_this, "", $key)); $consumerSecret = OAuth::$BEGIN_PRIVATE_KEY . "\n"; $chunks = str_split($rsa_private_key, 64); foreach ($chunks as $chunk) { $consumerSecret .= $chunk . "\n"; } $consumerSecret .= OAuth::$END_PRIVATE_KEY; } else { $consumerSecret = $key; } $cache->set(md5("RSA_KEY_" . $serviceName), $consumerSecret); } } $kas = new ConsumerKeyAndSecret($consumerKey, $consumerSecret, $keyType); $this->storeConsumerKeyAndSecret($gadgetUri, $serviceName, $kas); }
/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); $this->cache = Cache::createCache('CacheStorageFile', 'TestCache'); $this->service = new DefaultInvalidateService($this->cache); }
private function instanceRegistry() { // feature parsing is very resource intensive so by caching the result this saves upto 30% of the processing time $featureCache = Cache::createCache(Shindig_Config::get('feature_cache'), 'FeatureCache'); if (!($registry = $featureCache->get(md5(Shindig_Config::get('features_path'))))) { $registry = new GadgetFeatureRegistry(Shindig_Config::get('features_path')); $featureCache->set(md5(Shindig_Config::get('features_path')), $registry); } return $registry; }
die("Shindig requires the {$module} extention, see <a href='http://www.php.net/{$module}'>http://www.php.net/{$module}</a> for more info"); } } // Basic library requirements that are always needed require PartuzaConfig::get('library_root') . "/Image.php"; require PartuzaConfig::get('library_root') . "/Language.php"; require PartuzaConfig::get('library_root') . "/Database.php"; require PartuzaConfig::get('library_root') . "/Dispatcher.php"; require PartuzaConfig::get('library_root') . "/Controller.php"; require PartuzaConfig::get('library_root') . "/Model.php"; require PartuzaConfig::get('library_root') . "/Cache.php"; require PartuzaConfig::get('library_root') . "/CacheStorage.php"; require PartuzaConfig::get('library_root') . "/CacheStorageApc.php"; require PartuzaConfig::get('library_root') . "/CacheStorageFile.php"; require PartuzaConfig::get('library_root') . "/CacheStorageMemcache.php"; require PartuzaConfig::get('controllers_root') . "/base/base.php"; // Files copied from shindig, required to make the security token require PartuzaConfig::get('library_root') . "/Crypto.php"; require PartuzaConfig::get('library_root') . "/BlobCrypter.php"; require PartuzaConfig::get('library_root') . "/SecurityToken.php"; require PartuzaConfig::get('library_root') . "/BasicBlobCrypter.php"; require PartuzaConfig::get('library_root') . "/BasicSecurityToken.php"; // Initialize envirioment, and start the dispatcher Language::set(PartuzaConfig::get('language')); $db = new DB(PartuzaConfig::get('db_host'), PartuzaConfig::get('db_port'), PartuzaConfig::get('db_user'), PartuzaConfig::get('db_passwd'), PartuzaConfig::get('db_database'), false); $uri = $_SERVER["REQUEST_URI"]; $cache = Cache::createCache(PartuzaConfig::get('data_cache'), 'Partuza'); if (($pos = strpos($_SERVER["REQUEST_URI"], '?')) !== false) { $uri = substr($_SERVER["REQUEST_URI"], 0, $pos); } new Dispatcher($uri);
protected function instanceRegistry() { // feature parsing is very resource intensive so by caching the result this saves upto 30% of the processing time $featureCache = Cache::createCache(Config::get('feature_cache'), 'FeatureCache'); $key = md5(implode(',', Config::get('features_path'))); if (!($registry = $featureCache->get($key))) { $registry = new GadgetFeatureRegistry(Config::get('features_path')); $featureCache->set($key, $registry); } return $registry; }
/** * Tests Cache::createCache() */ public function testCreateCache() { $cache = Cache::createCache('CacheStorageFile', 'TestCache'); }