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());
 }
Exemple #2
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;
 }
    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];
    }
 /**
  * 执行函数
  * 
  * @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);
     }
 }
Exemple #5
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;
 }
Exemple #6
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);
 }
Exemple #7
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");
         }
     }
 }
 /**
  * @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;
     }
 }
 /**
  * 表初始化信息
  * 
  * @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'];
     }
 }
Exemple #10
0
 private function __construct()
 {
     $this->Cache = CacheFactory::getInstance();
     $this->getRulesList();
 }
 protected function getMetaModelCacheHandler()
 {
     return CacheFactory::getInstance()->getSharedCacheHandler($this->getCachePrefix());
 }