Пример #1
0
 /**
  * Store object in to the cache
  * @param mixed $obj - object to store
  * @param string $type - type of object entry/category/section
  * @param int $id - id of the object
  * @param int $sid
  * @param bool $force
  * @return SPCache
  */
 public function &addObj($obj, $type, $id, $sid = 0, $force = false)
 {
     if ($this->enabled(!$force)) {
         static $startTime = 0;
         if (!$startTime && class_exists('Sobi')) {
             $start = Sobi::Reg('start');
             $startTime = $start[1];
         }
         // storing need time - if we are over five seconds - skip
         if (!defined('SOBIPRO_ADM') && !$force && microtime(true) - $startTime > 5) {
             return $this;
         }
         // it was the idea that if entry has been taken from cache, and do not reports any changes - it doesn't have to be stored again
         // but I'm not so sure if this is a good idea any longer
         // so let's skip it and see what's going to happen
         // poor guys from the testing team :P
         // Tue, Feb 19, 2013 14:09:52
         // it makes sense - otherwise the cache is being invalidated again and again
         // anyway stupid solution -  i have to reconsider it therefore @todo
         if ($type == 'entry') {
             // entry has to report if it should be re-validate
             if (!isset($this->_check[$type][$id]) || !$this->_check[$type][$id]) {
                 return $this;
             }
         }
         $id = (int) $id;
         $sid = (int) $sid;
         $sid = $sid ? $sid : $this->_section;
         $loaded = serialize(SPLoader::getLoaded());
         $lang = Sobi::Lang(false);
         $checksum = null;
         //md5( serialize( $obj ) );
         if ($this->_apc) {
             $var = array('obj' => $obj, 'classes' => $loaded);
             apc_store("com_sobipro_{$sid}_{$id}_{$type}_{$lang}", $var);
         }
         $obj = SPConfig::serialize($obj);
         $schecksum = md5($obj);
         // the command is a "REPLACE" so there is actually no reason for deleting it anyway
         // the "deleteObj" causing however a chain reaction which would delete lot of other things so it doesn't make any sense here
         //			$this->deleteObj( $type, $id, $sid );
         $this->Exec("BEGIN; REPLACE INTO objects ( type, validtime, id, sid, lang, params, checksum, schecksum, data, classes ) VALUES( '{$type}', '0', '{$id}', '{$sid}', '{$lang}', NULL, '{$checksum}', '{$schecksum}', '{$obj}', '{$loaded}' ); COMMIT;");
         $this->cleanJCache();
     }
     return $this;
 }