/** * Инвалидирует кеш по тегам * @param array $tags список тегов * @param int|null $time метка времени Unix, когда теги стали невалидными. Если не указано, используется текущее время * @return self */ protected function invalidateCache(array $tags, $time = null) { if ($this->traitCache) { $this->traitCache->invalidateTags($tags, $time); } return $this; }
/** * Retrieves a value from the cache * @param string $objectclass * @param string $id * @return Phreezable */ public function GetCache($objectclass, $id) { if ($this->ObjectCacheTimeout <= 0) { return null; } $cachekey = $objectclass . "_" . $id; // include the model so any serialized classes will not throw an exception $this->IncludeModel($objectclass); // see if this object was cached in the level 1 cache $obj = $this->_level1Cache->Get($cachekey); if ($obj) { $this->Observe("Retrieved TYPE='{$objectclass}' ID='{$id}' from 1st Level Cache", OBSERVE_DEBUG); $obj->CacheLevel(1); if (!$obj->IsLoaded()) { $obj->Refresh($this); } return $obj; } // try the level 2 cahce $obj = $this->_level2Cache->Get($cachekey); if ($obj) { $this->Observe("Retrieved TYPE='{$objectclass}' ID='{$id}' from 2nd Level Cache", OBSERVE_DEBUG); $obj->Refresh($this); $obj->CacheLevel(2); // we just got this from level 2, but it wasn't in level 1 so let's save it in level 1 for $this->_level1Cache->Set($cachekey, $obj); return $obj; } $this->Observe("No L1/L2 Cache for TYPE='{$objectclass}' ID='{$id}'", OBSERVE_DEBUG); // $this->Observe("KEYS =" . serialize($this->_level1Cache->GetKeys()) ,OBSERVE_DEBUG); return null; }
/** * Handles the after unlocking export event. This writes into the cache the * new value * * @param AfterUnlockFileEvent $event */ public function onAfterUnlockFile(AfterUnlockFileEvent $event) { if ($event->isSuccess()) { if ($this->cache === null || !$this->cache instanceof ICache) { return; } $policy = $event->getPolicy(); if ($this->_count === null) { $count = $policy->getCount($event->getCriteriaBuilder()); } else { $count = $this->_count; } $key = $this->buildKey($policy, $event->getCriteriaBuilder()); if (!$this->cache->set($key, $count)) { $message = Yii::t('export.cache_exported_file_behavior', 'Impossible to save value "{value}" in cache for key "{key}".', array('{value}' => $count, '{key}' => $key)); Yii::log($message, CLogger::LEVEL_WARNING, 'export.cache_exported_file_behavior'); } } }
/** * Updates or invalidates cache entries after market data update * * @param int $typeID the ID of the item * @param int $regionID the ID of the region * @param \ArrayObject $timestamps with two elements carrying the UNIX timestamps * * @return void */ protected function updateCaches($typeID, $regionID, \ArrayObject $timestamps) { if (\iveeCore\Config::getUseCache()) { //update timestamps cache $this->cache->setItem($timestamps, 'emdrts_' . $regionID . '_' . $typeID); //invalidate the type cache for the item that was updated if its the default region if ($regionID == $this->defaultRegionID) { $this->cache->deleteItem('Type_' . $typeID); } } }
/** * Returns a PointcutDefinition or false if none found. * * @param string $pointcut Pointcut id or name. * * @return PointcutDefinition */ public function getPointcut($pointcut) { if (isset($this->_pointcuts[$pointcut])) { return $this->_pointcuts[$pointcut]; } else { $result = false; $value = $this->_cache->fetch('AspectManagerPointcut' . $pointcut, $result); if ($result === true) { $this->_pointcuts[$pointcut] = $value; return $value; } else { foreach ($this->_pointcutProviders as $provider) { $value = $provider->getPointcut($pointcut); if ($value !== false) { $this->setPointcut($value); return $value; } } } } return false; }
static function goods_category() { //获取商品分类缓存 $cacheObj = new ICache('file'); $catResult = $cacheObj->get('goodsCategory'); if ($catResult) { return $catResult; } $catResult = array(); $catObj = new IModel('category'); $catFirst = $catObj->query('parent_id = 0', 'id,name,parent_id,visibility', 'sort', 'asc'); $catOther = $catObj->query('parent_id != 0', 'id,name,parent_id,visibility', 'sort', 'asc'); foreach ($catFirst as $first_key => $first) { foreach ($catOther as $other_key => $other_val) { if ($first['id'] == $other_val['parent_id']) { //拼接二级分类 $first['second'][$other_key] = $other_val; //拼接二级以下所有分类 $catMore = array(); self::recursion_goods_category($other_val, $catOther, $catObj, $catMore); $first['second'][$other_key]['more'] = $catMore; } } $catResult[] = $first; } //写入缓存 $cacheObj->set('goodsCategory', $catResult); return $catResult; }
/** * @brief 分类排序 */ function category_sort() { $category_id = IFilter::act(IReq::get('id')); $sort = IFilter::act(IReq::get('sort')); //更新缓存 $cacheObj = new ICache('file'); $cacheObj->del('goodsCategory'); $flag = 0; if ($category_id) { $tb_category = new IModel('category'); $category_info = $tb_category->getObj('id=' . $category_id); if (count($category_info) > 0) { if ($category_info['sort'] != $sort) { $tb_category->setData(array('sort' => $sort)); if ($tb_category->update('id=' . $category_id)) { $flag = 1; } } } } echo $flag; }
/** * @brief 商品分类列表 */ function category_list() { $isCache = false; $tb_category = new IModel('category'); $cacheObj = new ICache('file'); $data = $cacheObj->get('sortdata'); if (!$data) { $goods = new goods_class(); $data = $goods->sortdata($tb_category->query(false, '*', 'sort', 'asc')); $isCache ? $cacheObj->set('sortdata', $data) : ""; } $this->data['category'] = $data; $this->setRenderData($this->data); $this->redirect('category_list', false); }
/** * @brief 【重要】支付回调[异步] */ function server_callback() { //从URL中获取支付方式 $payment_id = IFilter::act(IReq::get('_id'), 'int'); $paymentInstance = Payment::createPaymentInstance($payment_id); if (!is_object($paymentInstance)) { die('fail'); } //初始化参数 $money = ''; $message = '支付失败'; $orderNo = ''; //执行接口回调函数 $callbackData = array_merge($_POST, $_GET); unset($callbackData['controller']); unset($callbackData['action']); unset($callbackData['_id']); $return = $paymentInstance->serverCallback($callbackData, $payment_id, $money, $message, $orderNo); //支付成功 if ($return == 1) { //充值方式 if (stripos($orderNo, 'recharge') !== false) { $tradenoArray = explode('recharge', $orderNo); $recharge_no = isset($tradenoArray[1]) ? $tradenoArray[1] : 0; if (payment::updateRecharge($recharge_no)) { $paymentInstance->notifyStop(); exit; } } else { //读取批量订单付款 $cacheObj = new ICache('file'); $moreOrder = $cacheObj->get($orderNo); $moreOrder = $moreOrder ? explode(",", $moreOrder) : array($orderNo); foreach ($moreOrder as $key => $item) { $order_id = Order_Class::updateOrderStatus($item); if (!$order_id) { throw new IException("异步支付回调修改状态错误,订单ID:" . $order_id); } } $paymentInstance->notifyStop(); exit; } } else { $paymentInstance->notifyStop(); exit; } }
/** * @brief 获取订单中的支付信息 M:必要信息; R表示店铺; P表示用户; * @param $payment_id int 支付方式ID * @param $type string 信息获取方式 order:订单支付;recharge:在线充值; * @param $argument mix 参数 * @return array 支付提交信息 */ public static function getPaymentInfo($payment_id, $type, $argument) { //最终返回值 $payment = array(); //初始化配置参数 $paymentInstance = Payment::createPaymentInstance($payment_id); $configParam = $paymentInstance->configParam(); foreach ($configParam as $key => $val) { $payment[$key] = ''; } //获取公共信息 $paymentRow = self::getPaymentById($payment_id, 'config_param'); if ($paymentRow) { $paymentRow = JSON::decode($paymentRow); foreach ($paymentRow as $key => $item) { $payment[$key] = $item; } } if ($type == 'order') { $orderIdArray = $argument; $M_Amount = 0; $M_OrderNO = array(); foreach ($orderIdArray as $key => $order_id) { //获取订单信息 $orderObj = new IModel('order'); $orderRow = $orderObj->getObj('id = ' . $order_id . ' and status = 1'); if (empty($orderRow)) { IError::show(403, '订单信息不正确,不能进行支付'); } //判断商品库存 $orderGoodsDB = new IModel('order_goods'); $orderGoodsList = $orderGoodsDB->query('order_id = ' . $order_id); foreach ($orderGoodsList as $key => $val) { if (!goods_class::checkStore($val['goods_nums'], $val['goods_id'], $val['product_id'])) { IError::show(403, '商品库存不足无法支付,请重新下单'); } } $M_Amount += $orderRow['order_amount']; $M_OrderNO[] = $orderRow['order_no']; } $payment['M_Remark'] = $orderRow['postscript']; $payment['M_OrderId'] = $orderRow['id']; $payment['M_OrderNO'] = $orderRow['order_no']; $payment['M_Amount'] = $M_Amount; //用户信息 $payment['P_Mobile'] = $orderRow['mobile']; $payment['P_Name'] = $orderRow['accept_name']; $payment['P_PostCode'] = $orderRow['postcode']; $payment['P_Telephone'] = $orderRow['telphone']; $payment['P_Address'] = $orderRow['address']; //订单批量结算缓存机制 $cacheObj = new ICache('file'); $cacheObj->set($payment['M_OrderNO'], join(",", $M_OrderNO)); } else { if ($type == 'recharge') { if (ISafe::get('user_id') == null) { IError::show(403, '请登录系统'); } if (!isset($argument['account']) || $argument['account'] <= 0) { IError::show(403, '请填入正确的充值金额'); } $rechargeObj = new IModel('online_recharge'); $reData = array('user_id' => ISafe::get('user_id'), 'recharge_no' => Order_Class::createOrderNum(), 'account' => $argument['account'], 'time' => ITime::getDateTime(), 'payment_name' => $argument['paymentName']); $rechargeObj->setData($reData); $r_id = $rechargeObj->add(); //充值时用户id跟随交易号一起发送,以"_"分割 $payment['M_OrderNO'] = 'recharge' . $reData['recharge_no']; $payment['M_OrderId'] = $r_id; $payment['M_Amount'] = $reData['account']; } } $siteConfigObj = new Config("site_config"); $site_config = $siteConfigObj->getInfo(); //交易信息 $payment['M_Time'] = time(); $payment['M_Paymentid'] = $payment_id; //店铺信息 $payment['R_Address'] = isset($site_config['address']) ? $site_config['address'] : ''; $payment['R_Name'] = isset($site_config['name']) ? $site_config['name'] : ''; $payment['R_Mobile'] = isset($site_config['mobile']) ? $site_config['mobile'] : ''; $payment['R_Telephone'] = isset($site_config['phone']) ? $site_config['phone'] : ''; return $payment; }
public static function set($name, $value) { $key = self::key($name); self::$c_instance->set($key, $value); self::$c_cache[$key] = $value; }
/** * Returns a bean. * * @param string $name Bean name. * * @throws BeanFactoryException * @return object */ public function getBean($name) { $ret = false; $beanDefinition = $this->getBeanDefinition($name); $beanName = $name . '.bean'; if ($beanDefinition->isAbstract()) { throw new BeanFactoryException("Cant instantiate abstract bean: {$name}"); } if ($beanDefinition->isPrototype()) { $ret = $this->_createBean($beanDefinition); } else { if ($beanDefinition->isSingleton()) { if (isset($this->_beans[$beanName])) { $ret = $this->_beans[$beanName]; } else { $ret = $this->_beanCache->fetch($beanName, $result); if (!$ret) { $ret = $this->_createBean($beanDefinition); } $this->_beans[$beanName] = $ret; } } } return $ret; }