/** * Notify that observable object changed * * @param GitPHP_Observable_Interface $object object * @param int $changeType type of change * @param array $args argument array */ public function ObjectChanged($object, $changeType, $args = array()) { if (!$object) { return; } if ($changeType !== GitPHP_Observer_Interface::CacheableDataChange) { return; } if (!$this->cache) { return; } if (!($object instanceof GitPHP_Observable_Interface && $object instanceof GitPHP_Cacheable_Interface)) { return; } $this->cache->Set($object->GetCacheKey(), $object); }
public function testMemcachedLifetime() { if (!class_exists('Memcached')) { $this->markTestSkipped(); return; } $cache = new GitPHP_Cache(new GitPHP_Cache_Memcached(array(array('127.0.0.1', 11211)))); $cache->Clear(); $cache->Set('testkey1|testkey2', 'testvalue1', 1); sleep(2); $this->assertFalse($cache->Exists('testkey1|testkey2')); $cache->SetLifetime(1); $cache->Set('testkey3|testkey4', 'testvalue2'); sleep(2); $this->assertFalse($cache->Get('testkey3|testkey4')); }
/** * Get diff data * * @param integer $context number of context lines * @param boolean $header true to include file header * @param string $file override file name * @return string diff data */ private function GetDiffData($context = 3, $header = true, $file = null) { $fromData = ''; $toData = ''; if (empty($this->status) || $this->status == 'M' || $this->status == 'D') { $fromBlob = $this->GetFromBlob(); $fromData = $fromBlob->GetData(false); } if (empty($this->status) || $this->status == 'M' || $this->status == 'A') { $toBlob = $this->GetToBlob(); $toData = $toBlob->GetData(false); } $output = ''; if ($header) { $output = '--- ' . $this->GetFromLabel($file) . "\n" . '+++ ' . $this->GetToLabel($file) . "\n"; } $diffOutput = false; $cacheKey = null; if ($this->cache) { $cacheKey = 'project|' . $this->project->GetProject() . '|diff|' . $context . '|' . $this->fromHash . '|' . $this->toHash; $diffOutput = $this->cache->Get($cacheKey); } if ($diffOutput === false) { if ($this->UseXDiff()) { $diffOutput = $this->GetXDiff($fromData, $toData, $context); } else { $diffOutput = $this->GetPhpDiff($fromData, $toData, $context); } if ($this->cache) { $this->cache->Set($cacheKey, $diffOutput); } } $output .= $diffOutput; return $output; }