/** * 所有的查询的结果缓存30天 */ public function __construct() { parent::__construct(new Application_Model_Table_City()); //设置缓存一个月 try { $this->_select = $this->select()->setCacheClass(XF_Cache_Memcache::getInstance())->setCacheTime(60 * 24 * 30, FALSE); } catch (XF_Exception $e) { } }
/** * 验证指定的验证码是否有效 * @param string $smsCode 手机验证码 * @return bool */ public function smsCodeIsOk($mobile, $smsCode) { try { $mem = XF_Cache_Memcache::getInstance(); } catch (XF_Exception $e) { return false; } $code = $mem->read($mobile . '_' . $smsCode); return $code == $smsCode; }
public function __construct() { parent::__construct($this); try { $this->setCache(XF_Cache_Memcache::getInstance()); } catch (XF_Exception $e) { } parent::__construct($this); $this->_view->setResourcePath($this->static_url); }
/** * 设置数据缓存 * @access protected * @param mixed $data */ protected function _setDataCache($data, $saveFile) { if ($this->_data_cache_time > 0) { $mem = XF_Cache_Memcache::getInstance(); $mem->setCacheTime($this->_data_cache_time); $saveFile = md5($saveFile); $mem->add($saveFile, $data); } return true; }
/** * 发送验证码 * @param string $mobile 手机号码 * @param int $smsCode 验证码 * @throws XF_Exception */ public function sendSmsCode($mobile, $smsCode) { if (XF_String_Validate_Mobile::validate($mobile) == FALSE) { throw new XF_Exception('手机号码错误!'); } //获取模板 $event = $this->get(100); if ($event->status == '0') { return FALSE; } //短信 if ($event->status == '2') { if ($event->msm_tpl == '') { throw new XF_Exception('短信模板为空,无法发送!'); } $message = str_replace(array('{smsCode}', '{mobile}', '{hour}', '{minute}'), array($smsCode, $mobile, date('H'), date('i')), $event->msm_tpl); $status = $this->sendSms($mobile, $message, 'code'); if ($status == TRUE) { $mem = XF_Cache_Memcache::getInstance(); $mem->setCacheTime(10); $mem->add($mobile . '_' . $smsCode, $smsCode); } return $status; } return FALSE; }