protected function getMetaModelCacheHandler()
 {
     // we cannot use shared cache to store environment meta model for two reasons:
     //   - it could contain sensitive information such as password
     //   - Catch 22: we need environment meta model already in memory to access configuration of external cache
     return CacheFactory::getInstance()->getLocalCacheHandler($this->getCachePrefix());
 }
Esempio n. 2
0
 public static function factory($options)
 {
     $options = is_array($options) ? $options : array();
     //只实例化一个对象
     if (is_null(self::$cacheFactory)) {
         self::$cacheFactory = new cacheFactory();
     }
     $driver = isset($options['driver']) ? $options['driver'] : C("CACHE_TYPE");
     //静态缓存实例名称
     $driverName = md5_s($options);
     //对象实例存在
     if (isset(self::$cacheFactory->cacheList[$driverName])) {
         return self::$cacheFactory->cacheList[$driverName];
     }
     $class = 'Cache' . ucwords(strtolower($driver));
     //缓存驱动
     $classFile = YY_PATH . 'Cache/' . $class . '.class.php';
     //加载驱动类库文件
     if (!require_array($classFile)) {
         halt("缓存类型指定错误,不存在缓存驱动文件:" . $classFile);
     }
     $cacheObj = new $class($options);
     self::$cacheFactory->cacheList[$driverName] = $cacheObj;
     return self::$cacheFactory->cacheList[$driverName];
 }
Esempio n. 3
0
 /**
  * @static
  * @return CacheFactory
  */
 public static function getInstance()
 {
     if (!isset(self::$factory)) {
         self::$factory = new DefaultCacheFactory();
     }
     return self::$factory;
 }
Esempio n. 4
0
	public static function init()
	{		
		self::$c = CacheFactory::initCache();
		
		if (self::$c != null) return true;
		return false;
	}
 /**
  * @since 2.3
  *
  * @param string $poolCacheId
  * @param integer $cacheSize
  *
  * @return Cache
  */
 public function getPoolCacheById($poolCacheId, $cacheSize = 500)
 {
     if (!isset($this->poolCacheList[$poolCacheId])) {
         $this->poolCacheList[$poolCacheId] = $this->cacheFactory->newFixedInMemoryCache($cacheSize);
     }
     return $this->poolCacheList[$poolCacheId];
 }
Esempio n. 6
0
 public static function getInstance()
 {
     if (!static::$instance) {
         static::$instance = CacheFactory::factory();
     }
     return static::$instance;
 }
Esempio n. 7
0
 public function __construct()
 {
     $this->Session = Session::getInstance();
     $this->Rules = Rules::getInstance();
     $this->Cache = CacheFactory::factory();
     $this->tables = Config::read('modules.Session.User.Auth.tables');
     $this->auths = array();
 }
Esempio n. 8
0
 public function execute()
 {
     $this->rules = array();
     $Sql = Doctrine_Query::create()->select('id, name')->from('Rule');
     while ($data = $Sql->fetchArray()) {
         $this->rules[$data['id']] = $data['name'];
     }
     CacheFactory::factory()->store('system/rulesList', $this->rules, 0);
 }
Esempio n. 9
0
 public static function getInstance()
 {
     if (self::$Instance === null) {
         $type = self::getType();
         $class_name = "{$type}Cache";
         self::$Instance = new $class_name();
     }
     return self::$Instance;
 }
Esempio n. 10
0
 public function getCateGory()
 {
     $cache = CacheFactory::getInstance();
     $items = $cache->get("_GoodsCategory");
     if ($cache->get("_GoodsCategory") === null) {
         $items = $this->_CategoryInit(0);
         $cache->set("_GoodsCategory", $items, 315360000);
     }
     return $items;
 }
Esempio n. 11
0
 public function __construct()
 {
     parent::__construct();
     $this->handlerConfigurations = module_invoke_all('dc_cache');
     // preparing default value for cache entry expiration time
     $cacheConfigurationSection = Environment::getInstance()->getConfigurationSection('Cache');
     if (isset($cacheConfigurationSection['Entry Expiration']['Default'])) {
         AbstractCacheHandler::$DEFAULT__ENTRY_EXPIRATION = $cacheConfigurationSection['Entry Expiration']['Default'];
     }
 }
Esempio n. 12
0
 private function __construct()
 {
     $this->Cache = CacheFactory::factory();
     $this->Session = Session::getInstance();
     $this->table = Config::read('modules.Session.User.table');
     $this->anon_id = Config::read('modules.Session.User.anonymous_id');
     $this->autolog = (bool) Config::read('modules.Session.User.Autologin.' . 'enabled');
     if (Config::read('modules.Session.User.Auth.enabled') === true) {
         $this->Auth = new Auths();
     }
     $this->loadUser();
 }
Esempio n. 13
0
 /**
  * Returns parsed Factbox content from either the OutputPage property
  * or from the Cache
  *
  * @since 1.9
  *
  * @param OutputPage $outputPage
  *
  * @return string
  */
 public function retrieveContent(OutputPage $outputPage)
 {
     $text = '';
     $title = $outputPage->getTitle();
     if ($title instanceof Title && ($title->isSpecialPage() || !$title->exists())) {
         return $text;
     }
     if (isset($outputPage->mSMWFactboxText)) {
         $text = $outputPage->mSMWFactboxText;
     } elseif ($title instanceof Title) {
         $key = $this->cacheFactory->getFactboxCacheKey($title->getArticleID());
         $content = $this->retrieveFromCache($key);
         $text = isset($content['text']) ? $content['text'] : '';
     }
     return $text;
 }
    protected function getCacheOptions() {
        $cacheSynchronizationOptions = &drupal_static(__CLASS__ . '::cacheSynchronizationOptions');

        if (!isset($cacheSynchronizationOptions[$this->expirationTimePolicyName])) {
            $cacheKey = 'dp_cache_sync:' . $this->expirationTimePolicyName;
            $cache = CacheFactory::getInstance()->getSharedCacheHandler(get_class($this));

            $cacheSyncOptions = $cache->getValue($cacheKey);
            if (!isset($cacheSyncOptions)) {
                $isSourceDataUpdateInProgress = FALSE;
                $sourceDataAsOfDateTime = NULL;

                $syncOptions = module_invoke_all('dp_cache_sync', $this->expirationTimePolicyName);
                if (isset($syncOptions)) {
                    foreach ($syncOptions as $sourceDataOptions) {
                        if (!$isSourceDataUpdateInProgress && isset($sourceDataOptions[CacheHandler::OPTION__DATA_UPDATE_IN_PROGRESS])) {
                            $isSourceDataUpdateInProgress = $sourceDataOptions[CacheHandler::OPTION__DATA_UPDATE_IN_PROGRESS];
                        }
                        if (isset($sourceDataOptions[CacheHandler::OPTION__DATA_RESET_DATETIME])) {
                            $dt = $sourceDataOptions[CacheHandler::OPTION__DATA_RESET_DATETIME];
                            if (!isset($sourceDataAsOfDateTime) || ($sourceDataAsOfDateTime < $dt)) {
                                $sourceDataAsOfDateTime = $dt;
                            }
                        }
                    }
                }

                if ($isSourceDataUpdateInProgress) {
                    $cacheSyncOptions[CacheHandler::OPTION__DATA_UPDATE_IN_PROGRESS] = $isSourceDataUpdateInProgress;
                }
                if (isset($sourceDataAsOfDateTime)) {
                    $cacheSyncOptions[CacheHandler::OPTION__DATA_RESET_DATETIME] = $sourceDataAsOfDateTime;
                }

                // to prevent repeatable hook invocations
                if (!isset($cacheSyncOptions)) {
                    $cacheSyncOptions = FALSE;
                }

                $cache->setValue($cacheKey, $cacheSyncOptions);
            }
            $cacheSynchronizationOptions[$this->expirationTimePolicyName] = $cacheSyncOptions;
        }

        return ($cacheSynchronizationOptions[$this->expirationTimePolicyName] === FALSE) ? NULL : $cacheSynchronizationOptions[$this->expirationTimePolicyName];
    }
Esempio n. 15
0
 /**
  * 执行函数
  * 
  * @access public
  * @return mixed
  */
 public function run()
 {
     $method = $this->getAction();
     $args = $this->args;
     if ($this->cache == "true") {
         $cache = CacheFactory::getInstance();
         $content = $cache->get($method . $args);
         if ($content === null) {
             ob_start();
             ob_implicit_flush(false);
             $this->doMethod($method, $args);
             $content = ob_get_clean();
             $cache->set($method . $args, $content, intval($this->cacheTime));
         }
         echo $content;
     } else {
         $this->doMethod($method, $args);
     }
 }
 private static function create()
 {
     if (empty(self::$cacheInstance)) {
         $sCachingMethod = \General\Config::getInstance()->get('cacheMethod');
         if ($sCachingMethod === 'apc' && !(extension_loaded('apc') && ini_get('apc.enabled'))) {
             $sCachingMethod = 'Mem';
         }
         switch ($sCachingMethod) {
             case 'Apc':
                 self::$cacheInstance = Apc::getInstance();
                 break;
             case 'Memcached':
                 self::$cacheInstance = Memcached::getInstance();
                 break;
             default:
                 self::$cacheInstance = Variable::getInstance();
                 break;
         }
     }
 }
Esempio n. 17
0
 public static function initCache()
 {
     global $app_i;
     switch ($app_i['cache']) {
         case CC_NOCACHE:
             return null;
         case CC_APC:
             if (!isset(self::$_apc)) {
                 self::$_apc = new CApcCache();
                 return self::$_apc;
             }
             return self::$_apc;
         case CC_MEMCACHE:
             if (!isset(self::$_memcache)) {
                 self::$_memcache = new CMemCache();
                 return self::$_memcache;
             }
             return self::$_memcache;
     }
     return null;
 }
Esempio n. 18
0
 /**
  * @brief 取得查询结果
  * @return array
  */
 public function find()
 {
     if ($this->page) {
         $sql = "select {$this->distinct} {$this->fields} from {$this->table} {$this->join} {$this->where} {$this->group} {$this->having} {$this->order}";
         $pageSql = "select count(*) as total from {$this->table} {$this->join} {$this->where} {$this->group} {$this->having}";
         $pagesize = isset($this->pagesize) ? intval($this->pagesize) : 10;
         $pagelength = isset($this->pagelength) ? intval($this->pagelength) : 10;
         $items = $this->dbo->doSql($pageSql);
         $total = 0;
         if (is_array($items)) {
             $total = $items[0]['total'];
         }
         $plus = floor($pagelength / 2);
         $data = array('total_nums' => $total, 'pagesize' => $pagesize, 'plus' => $plus);
         $this->paging = new Paging($data);
         $first = $this->paging->getFirstRow();
         $sql .= ' limit ' . $first . ',' . $pagesize;
         return $this->dbo->doSql($sql);
     } else {
         $sql = "select {$this->distinct} {$this->fields} from {$this->table} {$this->join} {$this->where} {$this->group} {$this->having} {$this->order} {$this->limit}";
         $items = array();
         if ($this->cache) {
             $cache = CacheFactory::getInstance();
             $items = $cache->get("{$sql}");
             if ($items === null) {
                 $items = $this->dbo->doSql($sql);
                 $cache->set("{$sql}", $items, $this->cacheTime);
             }
         } else {
             try {
                 $items = $this->dbo->doSql($sql);
             } catch (Exception $e) {
                 throw $e;
             }
         }
         return $items;
     }
 }
 /**
  * Gets all elements by class
  * @param string $elementClass The element type searched
  * @param string $conditions The conditions string to apply (ex : Region.x < 10 AND World.size = 500)
  * @param string $orderBy The order string to apply (ex : 'Region.x, City.name DESC')
  * @return array The found element list array
  */
 public static function &getElementList($elementClass, $conditions = NULL, $orderBy = NULL, $join = NULL)
 {
     $logInstance = LogTool::getInstance();
     $logInstance->logDebug('Gets ' . $elementClass . ' list (conditions="' . $conditions . '", order="' . $orderBy . '")');
     // Tries to get element list from cache
     if ($join === NULL) {
         try {
             return CacheFactory::getElementList($elementClass, $conditions, $orderBy);
         } catch (ElementFactoryException $e) {
         }
     }
     // Gets element list from database
     list($elementList, $retrievedElementList) = DatabaseFactory::getElementList($elementClass, $conditions, $orderBy, $join);
     // Adds result to cache
     CacheFactory::addElementList($elementClass, $elementList, $conditions, $orderBy);
     if ($join !== NULL) {
         foreach ($retrievedElementList as $mainElementTableName => $mainElementElementList) {
             foreach ($mainElementElementList as $mainElementId => $attachedElementList) {
                 foreach ($attachedElementList as $childElementTableName => $childElementList) {
                     // Builds parent id conditions to cache list
                     $parentIdFieldName = DatabaseFactory::getParentIdColumnName(DatabaseFactory::getElementClassName($mainElementTableName));
                     $childRequestConditions = $childElementTableName . '.' . $parentIdFieldName . '=' . $mainElementId;
                     CacheFactory::addElementList(DatabaseFactory::getElementClassName($childElementTableName), $childElementList, $childRequestConditions, $orderBy);
                 }
             }
         }
     }
     return $elementList;
 }
 function __construct()
 {
     $cacheFactory = new CacheFactory();
     $this->cache = $cacheFactory->createCache();
 }
 /**
  * Resets cache
  */
 public static function clear()
 {
     self::$cachedElementArray = array();
     self::$cachedElementListArray = array();
 }
Esempio n. 22
0
File: Boot.php Progetto: jyht/v5
 public static function factory($options)
 {
     $options = is_array($options) ? $options : array();
     if (is_null(self::$cacheFactory)) {
         self::$cacheFactory = new cacheFactory();
     }
     $driver = isset($options['driver']) ? $options['driver'] : C("CACHE_TYPE");
     $driverName = md5_d($options);
     if (isset(self::$cacheFactory->cacheList[$driverName])) {
         return self::$cacheFactory->cacheList[$driverName];
     }
     $class = 'Cache' . ucwords(strtolower($driver));
     $classFile = HDPHP_DRIVER_PATH . 'Cache/' . $class . '.class.php';
     if (!require_cache($classFile)) {
         throw_exception("缓存类型指定错误,不存在缓存驱动文件:" . $classFile);
     }
     $cacheObj = new $class($options);
     self::$cacheFactory->cacheList[$driverName] = $cacheObj;
     return self::$cacheFactory->cacheList[$driverName];
 }
Esempio n. 23
0
 public function areas()
 {
     $cache = CacheFactory::getInstance();
     $items = $cache->get("_AreaData");
     if ($items == null) {
         $items = JSON::encode($this->_AreaInit(0));
         $cache->set("_AreaData", $items, 315360000);
     }
     return $items;
 }
Esempio n. 24
0
 public function area_op()
 {
     $id = Filter::int(Req::args('id'));
     $op = Req::args('op');
     $model = new Model('area');
     $cache = CacheFactory::getInstance();
     $info = array('status' => 'success', 'msg' => '');
     switch ($op) {
         case 'up':
         case 'down':
             $area = $model->where('id=' . $id)->find();
             $objs = $model->where('parent_id=' . $area['parent_id'])->order('sort')->findAll();
             $perv = $curr = $next = false;
             $last = end($objs);
             reset($objs);
             foreach ($objs as $obj) {
                 if ($area['id'] == $obj['id']) {
                     $curr = $obj;
                     if ($curr['id'] == $last['id']) {
                         $next = false;
                         end($objs);
                         $prev = prev($objs);
                     } else {
                         $next = current($objs);
                         $prev = prev($objs);
                         $prev = prev($objs);
                     }
                     break;
                 }
             }
             if ($op == 'up') {
                 if ($prev) {
                     $curr_sort = $prev['sort'];
                     $prev_sort = $curr['sort'];
                     $model->data(array('sort' => $curr_sort))->where('id=' . $curr['id'])->update();
                     $model->data(array('sort' => $prev_sort))->where('id=' . $prev['id'])->update();
                     $cache->delete("_AreaData");
                 }
             } else {
                 if ($next) {
                     $curr_sort = $next['sort'];
                     $next_sort = $curr['sort'];
                     $model->data(array('sort' => $curr_sort))->where('id=' . $curr['id'])->update();
                     $model->data(array('sort' => $next_sort))->where('id=' . $next['id'])->update();
                     $cache->delete("_AreaData");
                 }
             }
             $info = array('status' => 'success', 'msg' => '排序已更新');
             break;
         case 'add':
             $objs = $model->fields('max(sort) as sort')->where('parent_id=' . $id)->query();
             if ($objs) {
                 $sort = $objs[0]['sort'];
                 $sort++;
             } else {
                 $sort = 1;
             }
             $name = Filter::sql(Req::args('name'));
             $model->data(array('name' => $name, 'parent_id' => $id, 'sort' => $sort))->insert();
             $cache->delete("_AreaData");
             $info = array('status' => 'success', 'msg' => '成功添加节点');
             break;
         case 'edit':
             $name = Filter::sql(Req::args('name'));
             $model->data(array('name' => $name))->where('id=' . $id)->update();
             $cache->delete("_AreaData");
             $info = array('status' => 'success', 'msg' => '节点已更新');
             break;
         case 'del':
             $obj = $model->where('parent_id=' . $id)->find();
             if (!$obj) {
                 $model->where('id=' . $id)->delete();
                 $cache->delete("_AreaData");
                 $info = array('status' => 'success', 'msg' => '节点已经删除');
             } else {
                 $info = array('status' => 'fail', 'msg' => '子节点还有节点,无法删除');
             }
             break;
     }
     echo JSON::encode($info);
 }
Esempio n. 25
0
 function goods_category_del()
 {
     $id = Req::args('id');
     $category = new Model("goods_category");
     $child = $category->where("parent_id = {$id}")->find();
     if ($child) {
         $this->msg = array("warning", "由于存在子分类,此分类不能删除,操作失败!");
         $this->redirect("goods_category_list", false);
     } else {
         $goods = new Model("goods");
         $row = $goods->where('category_id = ' . $id)->find();
         if ($row) {
             $this->msg = array("warning", "此分类下还有商品,无法删除!");
             $this->redirect("goods_category_list", false);
         } else {
             $obj = $category->where("id={$id}")->find();
             $category->where("id={$id}")->delete();
             if ($obj) {
                 Log::op($this->manager['id'], "删除商品分类", "管理员[" . $this->manager['name'] . "]:删除了商品分类 " . $obj['name']);
             }
             $cache = CacheFactory::getInstance();
             $cache->delete("_GoodsCategory");
             $this->redirect("goods_category_list");
         }
     }
 }
Esempio n. 26
0
 /**
  * 表初始化信息
  * 
  * @access private
  * @return mixed
  */
 private function initTableInfo()
 {
     if (empty($this->fields)) {
         $cache = CacheFactory::getInstance();
         $info = $cache->get('table_' . $this->sql['table']);
         if (!$info) {
             $info = $this->db->getTableInfo($this->sql['table']);
             $cache->set('table_' . $this->sql['table'], $info, 86400);
         }
         $this->primary_key = $info['primary_key'];
         $this->fields = $info['fields'];
     }
 }
 public function __construct() {
     parent::__construct();
     $this->handlerConfigurations = module_invoke_all('dp_cache');
 }
Esempio n. 28
0
 /**
  * injects the Cache Manager
  * 
  * @return Cache The cache object or null
  */
 public function setCacheManager()
 {
     $config = $this->loadConfig();
     $cache = CacheFactory::get($config['cache']['type']);
     $cache->setPrefix($config['cache']['prefix']);
     return $cache;
 }
 /**
  * Gets all elements by type from database
  * @param string $elementClass The element type searched
  * @param string $conditions The conditions string to apply (ex : Region.x < 10 AND World.size = 500)
  * @param string $orderBy The order string to apply (ex : 'Region.x, City.name DESC')
  * @param string $join the joined tables
  * @return array The element list
  */
 public static function getElementList($elementClass, $conditions = NULL, $orderBy = NULL, $join = NULL)
 {
     $tableName = DatabaseFactory::getElementTableName($elementClass);
     if ($join !== NULL) {
         list($select, $from, $joinTableNameList, $joinTableAttachements) = DatabaseFactory::getJoin($tableName, $join);
         $request = 'SELECT ' . $select . $from;
     } else {
         $request = 'SELECT * FROM ' . $tableName;
     }
     if ($conditions !== NULL) {
         $request .= ' WHERE ' . $conditions;
     }
     if ($orderBy !== NULL) {
         $request .= ' ORDER BY ' . $orderBy;
     }
     $databaseConnection = $elementClass::getDatabaseConnection();
     // For join requests, needs to fetch results by index (to handle several fields with same name)
     if ($join === NULL) {
         // Execute request on database
         $resultType = MysqlDatabaseConnectionModel::ARRAY_TYPE_ASSOC;
         $resultList = $databaseConnection->selectRequest($request, $resultType, false, false);
     } else {
         // Gets field list with resut to get them for joined tables
         $resultType = MysqlDatabaseConnectionModel::ARRAY_TYPE_NUM;
         list($resultList, $fieldNameList) = $databaseConnection->selectRequest($request, $resultType, TRUE, FALSE);
         // Builds main element field list
         $fieldIndex = 0;
         $fieldNumber = count($fieldNameList);
         $elementFieldNameList = array();
         while ($fieldIndex < $fieldNumber) {
             $fieldName = $fieldNameList[$fieldIndex++];
             if (StringTool::endsWith($fieldName, DatabaseFactory::JOIN_TABLE_FIELD_SEPARATOR)) {
                 break;
             }
             $elementFieldNameList[$tableName][] = $fieldName;
         }
         // Builds joined elements field list
         foreach ($joinTableNameList as &$joinTableName) {
             while ($fieldIndex < $fieldNumber) {
                 $fieldName = $fieldNameList[$fieldIndex++];
                 if (StringTool::endsWith($fieldName, DatabaseFactory::JOIN_TABLE_FIELD_SEPARATOR)) {
                     break;
                 }
                 $elementFieldNameList[$joinTableName][] = $fieldName;
             }
         }
     }
     // Constructs typed elements from results
     $elementList = array();
     $retrievedElementList = array();
     while ($result = MysqlDatabaseConnectionModel::fetch_array($resultList, $resultType)) {
         $rowElementList = array();
         if ($join === NULL) {
             // Sets element
             $element = Element::getElementFromArray($elementClass, $result);
             $element->setId();
             $elementList[$element->id] = $element;
         } else {
             // Additionnal tables requested
             $fieldIndex = 0;
             $fieldValues = array_values($result);
             $rowElementList = array();
             // Sets elements attributes for each table on the row
             foreach ($elementFieldNameList as $elementTableName => $fieldNameList) {
                 $elementAttributeList = array();
                 foreach ($fieldNameList as $fieldName) {
                     $elementAttributeList[$fieldName] = $fieldValues[$fieldIndex++];
                 }
                 // Go next to avoid separator field
                 ++$fieldIndex;
                 // Sets element
                 $element = Element::getElementFromArray(DatabaseFactory::getElementClassName($elementTableName), $elementAttributeList);
                 $element->setId();
                 // Ignores empty LJ elements from "_has_" tables
                 if ($element->id == '-') {
                     continue;
                 }
                 // Adds it to element list if it is the main table
                 if ($tableName == $elementTableName && !ArrayTool::array_key_exists($element->id, $elementList)) {
                     $elementList[$element->id] = $element;
                 }
                 $rowElementList[$elementTableName] = $element;
             }
             // Attaches elements with each other
             foreach ($rowElementList as $rowElementTable => $rowElement) {
                 CacheFactory::addElement($rowElement);
                 // Checks if element has to be attached to another one
                 if (isset($joinTableAttachements[$rowElementTable])) {
                     foreach ($joinTableAttachements[$rowElementTable] as &$joinTableAttachement) {
                         if (isset($rowElementList[$joinTableAttachement])) {
                             if ($rowElementList[$joinTableAttachement]->getElementClass() != $rowElement->getElementClass() || $rowElementList[$joinTableAttachement]->id != $rowElement->id) {
                                 $retrievedElementList[$joinTableAttachement][$rowElementList[$joinTableAttachement]->id][$rowElementTable][$rowElement->id] = $rowElement;
                             }
                         }
                     }
                 }
             }
         }
     }
     MysqlDatabaseConnectionModel::free_result($resultList);
     return array($elementList, $retrievedElementList);
 }
Esempio n. 30
0
 /**
  * 设置连接驱动
  * @param array $options 参数
  * @return obj
  */
 public static function init($options = array())
 {
     return CacheFactory::factory($options);
     //获得缓存操作对象
 }