public function testCacheDefault()
 {
     Cache::set_cache_lifetime('default', 1200);
     $default = Cache::get_cache_lifetime('default');
     $this->assertEquals(1200, $default['lifetime']);
     $cache = Cache::factory('somethingnew');
     $this->assertEquals(1200, $cache->getOption('lifetime'));
 }
 /**
  * Get the cache object to use when storing / retrieving partial cache blocks.
  *
  * @return Zend_Cache_Core
  */
 public function getPartialCacheStore()
 {
     return $this->partialCacheStore ? $this->partialCacheStore : Cache::factory('cacheblock');
 }
 /**
  * Return the version number of this application.
  * Uses the number in <mymodule>/silverstripe_version
  * (automatically replaced by build scripts).
  * If silverstripe_version is empty,
  * then attempts to get it from composer.lock
  *
  * @return string
  */
 public function CMSVersion()
 {
     $versions = array();
     $modules = array('silverstripe/framework' => array('title' => 'Framework', 'versionFile' => FRAMEWORK_PATH . '/silverstripe_version'));
     if (defined('CMS_PATH')) {
         $modules['silverstripe/cms'] = array('title' => 'CMS', 'versionFile' => CMS_PATH . '/silverstripe_version');
     }
     // Tries to obtain version number from composer.lock if it exists
     $composerLockPath = BASE_PATH . '/composer.lock';
     if (file_exists($composerLockPath)) {
         $cache = Cache::factory('LeftAndMain_CMSVersion');
         $cacheKey = filemtime($composerLockPath);
         $versions = $cache->load($cacheKey);
         if ($versions) {
             $versions = json_decode($versions, true);
         } else {
             $versions = array();
         }
         if (!$versions && ($jsonData = file_get_contents($composerLockPath))) {
             $lockData = json_decode($jsonData);
             if ($lockData && isset($lockData->packages)) {
                 foreach ($lockData->packages as $package) {
                     if (array_key_exists($package->name, $modules) && isset($package->version)) {
                         $versions[$package->name] = $package->version;
                     }
                 }
                 $cache->save(json_encode($versions), $cacheKey);
             }
         }
     }
     // Fall back to static version file
     foreach ($modules as $moduleName => $moduleSpec) {
         if (!isset($versions[$moduleName])) {
             if ($staticVersion = file_get_contents($moduleSpec['versionFile'])) {
                 $versions[$moduleName] = $staticVersion;
             } else {
                 $versions[$moduleName] = _t('LeftAndMain.VersionUnknown', 'Unknown');
             }
         }
     }
     $out = array();
     foreach ($modules as $moduleName => $moduleSpec) {
         $out[] = $modules[$moduleName]['title'] . ': ' . $versions[$moduleName];
     }
     return implode(', ', $out);
 }
 public function tearDown()
 {
     $cache = Cache::factory('GDBackend_Manipulations');
     $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     parent::tearDown();
 }
Пример #5
0
 /**
  * Tests the integrity of the manipulation cache when an error occurs
  */
 public function testCacheIntegrity()
 {
     $fullPath = realpath(dirname(__FILE__) . '/gdtest/nonimagedata.jpg');
     // Load invalid file
     $gd = new GDBackend();
     $gd->loadFrom($fullPath);
     // Cache should refer to this file
     $cache = Cache::factory('GDBackend_Manipulations');
     $key = sha1(implode('|', array($fullPath, filemtime($fullPath))));
     $data = $cache->load($key);
     $this->assertEquals('1', $data);
 }
 public static function flush()
 {
     // Clear factory
     $cache = Cache::factory('GDBackend_Manipulations');
     $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
 }
 protected function _reset($cacheOn = true)
 {
     $this->data = new SSViewerCacheBlockTest_Model();
     Cache::factory('cacheblock')->clean();
     Cache::set_cache_lifetime('cacheblock', $cacheOn ? 600 : -1);
 }
 /**
  * Provides a hook for mock unit tests despite no DI
  * @return Zend_Cache_Core
  */
 protected function getCache()
 {
     return Cache::factory('SS_Configuration', 'Core', array('automatic_serialization' => true, 'lifetime' => null));
 }
Пример #9
0
 /**
  * Return an instance of the cache used for i18n data.
  *
  * @skipUpgrade
  * @return Zend_Cache_Core
  */
 public static function get_cache()
 {
     return Cache::factory('i18n', 'Output', array('lifetime' => null, 'automatic_serialization' => true));
 }