public function mediaAction()
 {
     echo "clearing media cache, this can take some time...\n";
     Kwf_Media_MemoryCache::getInstance()->clean();
     echo "done\n";
     exit;
 }
 public function mediaAction()
 {
     echo "clearing media cache, this can take some time...\n";
     Kwf_Media_MemoryCache::getInstance()->clean();
     echo "done\n";
     $ev = new Kwf_Events_Event_Media_ClearAll('Kwf_Media_MemoryCache');
     Kwf_Events_Dispatcher::fireEvent($ev);
     exit;
 }
Example #3
0
 protected function _init($componentClass)
 {
     Kwf_Component_Data_Root::setComponentClass($componentClass);
     Zend_Session::$_unitTestEnabled = true;
     $this->_root = Kwf_Component_Data_Root::getInstance();
     $this->_root->setFilename('kwf/kwctest/' . $componentClass);
     if (function_exists('apc_clear_cache')) {
         apc_clear_cache('user');
     }
     Kwf_Component_Cache_Memory::getInstance()->_clean();
     Kwf_Cache_Simple::resetZendCache();
     Kwc_FulltextSearch_MetaModel::setInstance(new Kwf_Model_FnF(array('primaryKey' => 'page_id')));
     Kwf_Assets_Package_Default::clearInstances();
     Kwf_Component_LogDuplicateModel::setInstance(new Kwf_Model_FnF(array()));
     Kwf_Media_MemoryCache::getInstance()->clean();
     return $this->_root;
 }
 public static function setInstance($instance)
 {
     self::$_instance = $instance;
 }
Example #5
0
 private static function _getOutputWithoutCheckingIsValid($class, $id, $type)
 {
     $cacheId = self::createCacheId($class, $id, $type);
     $output = Kwf_Media_MemoryCache::getInstance()->load($cacheId);
     if ($output && !isset($output['file']) && !isset($output['contents'])) {
         //scaled image is not cached in apc as it might be larger - load from disk
         $output['file'] = 'cache/media/' . $cacheId;
     }
     if (isset($output['file']) && !file_exists($output['file'])) {
         $output = false;
     }
     if ($output && isset($output['mtimeFiles'])) {
         foreach ($output['mtimeFiles'] as $f) {
             if (filemtime($f) > $output['mtime']) {
                 Kwf_Media_MemoryCache::getInstance()->remove($cacheId);
                 $output = false;
                 break;
             }
         }
     }
     if (!$output) {
         $classWithoutDot = strpos($class, '.') ? substr($class, 0, strpos($class, '.')) : $class;
         if (!Kwf_Loader::isValidClass($classWithoutDot) || !is_instance_of($classWithoutDot, 'Kwf_Media_Output_Interface')) {
             throw new Kwf_Exception_NotFound();
         }
         $output = call_user_func(array($classWithoutDot, 'getMediaOutput'), $id, $type, $class);
         $specificLifetime = false;
         $useCache = true;
         if (isset($output['lifetime'])) {
             $specificLifetime = $output['lifetime'];
             if (!$output['lifetime']) {
                 $useCache = false;
             }
         }
         if (!isset($output['mtime'])) {
             if (isset($output['file'])) {
                 $output['mtime'] = filemtime($output['file']);
             } else {
                 if (isset($output['mtimeFiles'])) {
                     $output['mtime'] = 0;
                     foreach ($output['mtimeFiles'] as $f) {
                         $output['mtime'] = max($output['mtime'], filemtime($f));
                     }
                 } else {
                     $output['mtime'] = time();
                 }
             }
         }
         if ($useCache) {
             $cacheData = $output;
             if (isset($cacheData['contents']) && strlen($cacheData['contents']) > 20 * 1024) {
                 //don't cache contents larger than 20k in apc, use separate file cache
                 file_put_contents('cache/media/' . $cacheId, $cacheData['contents']);
                 unset($cacheData['contents']);
             }
             Kwf_Media_MemoryCache::getInstance()->save($cacheData, $cacheId, $specificLifetime);
         }
     }
     return $output;
 }
 private static function _getOutputWithoutCheckingIsValid($class, $id, $type)
 {
     $cacheId = self::createCacheId($class, $id, $type);
     $output = Kwf_Media_MemoryCache::getInstance()->load($cacheId);
     if ($output && !isset($output['file']) && !isset($output['contents'])) {
         //cache entry from older kwf version where file was not set
         $output = false;
     }
     if (isset($output['file']) && !file_exists($output['file'])) {
         $output = false;
     }
     if ($output && isset($output['mtimeFiles'])) {
         foreach ($output['mtimeFiles'] as $f) {
             if (filemtime($f) > $output['mtime']) {
                 Kwf_Media_MemoryCache::getInstance()->remove($cacheId);
                 $output = false;
                 break;
             }
         }
     }
     if (!$output) {
         $classWithoutDot = strpos($class, '.') ? substr($class, 0, strpos($class, '.')) : $class;
         if (!Kwf_Loader::isValidClass($classWithoutDot) || !is_instance_of($classWithoutDot, 'Kwf_Media_Output_Interface')) {
             throw new Kwf_Exception_NotFound();
         }
         $output = call_user_func(array($classWithoutDot, 'getMediaOutput'), $id, $type, $class);
         $specificLifetime = false;
         $useCache = true;
         if (isset($output['lifetime'])) {
             $specificLifetime = $output['lifetime'];
             if (!$output['lifetime']) {
                 $useCache = false;
             }
         }
         if (!isset($output['mtime'])) {
             if (isset($output['file'])) {
                 $output['mtime'] = filemtime($output['file']);
             } else {
                 if (isset($output['mtimeFiles'])) {
                     $output['mtime'] = 0;
                     foreach ($output['mtimeFiles'] as $f) {
                         $output['mtime'] = max($output['mtime'], filemtime($f));
                     }
                 } else {
                     $output['mtime'] = time();
                 }
             }
         }
         if ($useCache) {
             $cacheData = $output;
             if (isset($cacheData['contents']) && strlen($cacheData['contents']) > 20 * 1024) {
                 //don't cache contents larger than 20k in apc, use separate file cache
                 $cacheFileName = Kwf_Config::getValue('mediaCacheDir') . '/' . $class . '/' . $id . '/' . $type;
                 if (!is_dir(dirname($cacheFileName))) {
                     @mkdir(dirname($cacheFileName), 0777, true);
                 }
                 file_put_contents($cacheFileName, $cacheData['contents']);
                 $cacheData['file'] = $cacheFileName;
                 unset($cacheData['contents']);
             }
             Kwf_Media_MemoryCache::getInstance()->save($cacheData, $cacheId, $specificLifetime);
         }
     }
     return $output;
 }