public static function initalize($engine = 'Cache_Static') { try { // Handle engine failover here switch ($engine) { case 'Cache_StaticMemcache': if (Cache_StaticMemcache::isEnabled()) { break; } case 'Cache_Memcache': if (Cache_Memcache::isEnabled()) { break; } case 'Cache_Static': default: $engine = 'Cache_Static'; } if (is_null(Cache::$Instance)) { Cache::$Instance = new $engine(); } } catch (Exception $e) { //if (Conf::read('DEBUG')) { // throw $e; //} else { return null; //} } }
/** * Constructs the memcache object * * @param array configuration * @throws Kohana_Cache_Exception */ protected function __construct(array $config) { if (!method_exists($this->_memcache, 'tag_add')) { throw new Kohana_Cache_Exception('Memcached-tags PHP plugin not present. Please see http://code.google.com/p/memcached-tags/ for more information'); } parent::__construct($config); }
/** * 工厂模式实例化常用缓存类 * * @access public * * @param string $adapter 缓存类型 * @param array $options 参数 * * @return object */ public static function factory($adapter, $options = null) { //参数分析 if (!$adapter) { return false; } $adapter = trim($adapter); $object = false; //分析缓存引擎 switch ($adapter) { case 'Memcache': $object = Cache_Memcache::getInstance($options); break; case 'Redis': $object = Cache_Redis::getInstance($options); break; case 'File': case 'Apc': case 'Xcache': case 'Wincache': case 'Eaccelerator': $object = Doit::singleton('Cache_' . $adapter); break; } return $object; }
/** * @return Help_Memcache */ public static function getInstance() { if (self::$_Instance == null) { self::$_Instance = new self(); } return self::$_Instance; }
function __construct() { $this->mem = Cache_Memcache::getInstance(); $this->mem->init(); if (($this->bwl = $this->mem->get("BlackWordList")) == false) { $this->getBlackWordListFromDB(); } }
public function __construct() { if (Sp_Admin_User::isLogin() === FALSE) { header("Location: " . SP_URL_CDGN . "login/index.html"); exit; } $userArr = Sp_Admin_User::getUser(); $user_id = $userArr['id']; //单点登录验证 $session_id = $_COOKIE['session_id']; $cache = Cache_Memcache::getInstance(); $SSO_memcache_key = 'SSO_admin_user_' . $user_id; $SSO_memcache_data = $cache->get($SSO_memcache_key); if ($session_id != $SSO_memcache_data && !empty($SSO_memcache_data) && $user_id != 1) { echo "<script type='text/javascript'>"; echo "alert('您的账号在其他地方登录,已被踢下线!');"; echo "location.href = '" . SP_URL_DESK . "login/signout.html'"; echo "</script>"; exit; } $spAdminUser = new Sp_Admin_User(); $userInfo = $spAdminUser->adminuser_getUserAndRole($user_id, DATA_TYPE); if ($userInfo['groupid'] > 0 && $userInfo['cdgn_del'] >= 0 || $userInfo['groupid'] == 1) { define('CDGN_GROUP', '1'); } if ($userInfo['custom_groupid'] > 0 && $userInfo['custom_del'] >= 0 || $userInfo['groupid'] == 1) { define('CUSTOM_GROUP', '1'); } if ($userInfo['ad_groupid'] > 0 && $userInfo['ad_del'] >= 0 || $userInfo['groupid'] == 1) { define('AD_GROUP', '1'); } if ($userInfo['cs_groupid'] > 0 && $userInfo['cs_del'] >= 0 || $userInfo['groupid'] == 1) { define('CS_GROUP', '1'); } if ($userInfo['groupid'] == 1) { define('CS_SYSTEM', '1'); } if ($userInfo[STATUS_DEL] != 0) { echo "<script type='text/javascript'>"; echo "alert('您在该管理系统没有权限,或者是被移除!')"; echo "</script>"; exit; } if ($userInfo['groupid'] == 1) { $this->_isAdmin = TRUE; } if ($userInfo['groupid'] != 1) { $spAdminRole = new Sp_Admin_Role(); $spGroupInfo = $spAdminRole->adminuser_getGroupRole($userInfo[GROUP_NAME]); $spAdminGroupRole = is_array($spGroupInfo['rolelist']) && count($spGroupInfo['rolelist']) > 0 ? $spGroupInfo['rolelist'] : array(); $spUserRole = is_array($userInfo['rolelist']) && count($userInfo['rolelist']) > 0 ? $userInfo['rolelist'] : array(); $spRoleList = array_merge($spAdminGroupRole, $spUserRole); $this->_roleList = $spRoleList; $spFormatRoleList = array(); foreach ($spRoleList as $val) { $spFormatRoleList[] = $val['m'] . DIRECTORY_SEPARATOR . $val['c']; } $requestUriArr = str_replace("/custom", "", $_SERVER['REQUEST_URI']); $requestUriArr = explode('.', $requestUriArr); $userPath = str_replace('/', DIRECTORY_SEPARATOR, ltrim(ltrim($requestUriArr[0], '/'), '\\')); $userPath = str_replace('\\', DIRECTORY_SEPARATOR, $userPath); $checkList = explode(DIRECTORY_SEPARATOR, $userPath); if ($userPath != '' && !in_array($userPath, $spFormatRoleList) && !Sp_Admin_Menu::checkWhiteList($checkList[0], $checkList[1])) { echo "<script type='text/javascript'>"; echo "alert('您没有获得该权限!');"; echo "location.href = '" . SP_URL_DESK . "';"; echo "</script>"; exit; } } }
/** * 返回 Cache 对象 * * @return object */ protected function getCacheInstance() { if ($this->_cacheobj === null) { $this->_cacheobj = Cache_Memcache::getInstance(); } return $this->_cacheobj; }
/** * consistent hashing */ public static function addServer($host, $port = 11211, $weight = 1, $timeout = 1) { $weight = $weight * 10; for ($i = 1; $i <= $weight; $i++) { $serverid = self::hash($host . ":" . $port . ":" . $i); self::$_servers[] = array("host" => $host, "port" => $port, "weight" => $weight, "id" => $serverid, "timeout" => $timeout); } usort(self::$_servers, "self::_sort"); self::$_serverCt = count(self::$_servers); }
public static function isEnabled() { return Cache_Static::isEnabled() && Cache_Memcache::isEnabled(); }
/** * 单例模式 * * 用于本类的单例模式(singleton)实例化 * * @access public * * @param array $params 数据库连接参数 * * @return object */ public static function getInstance($params = null) { if (!self::$_instance) { self::$_instance = new self($params); } return self::$_instance; }
/** * 取缓存 * @param $pKey * @param $pVal * @param int $pExp * @return bool */ static function set($pKey, $pVal, $pExp = 3600) { return Cache_Memcache::instance()->set($pKey, $pVal, $pExp); }
function __construct() { $this->_isChanged = false; $this->_gCacheStorage = array(); $this->context = Model_Context::getInstance(); $this->__usePageCache = $this->context->getProperty('service.pagecache'); $this->_gBlogId = getBlogId(); if ($this->context->getProperty('service.memcached') == true) { $this->pool = Cache_Memcache::getInstance(); } else { $this->pool = DBModel::getInstance(); } }
/** * 执行SQL,并返回结果 */ function query() { $tArgs = func_get_args(); $tSql = array_shift($tArgs); # 锁表查询 if ($this->_lock) { $tSql .= ' ' . $this->_lock; $this->_lock = ''; } # 使用缓存 if ($this->cache) { $tMem =& Cache_Memcache::instance('default'); if ('md5' == $this->cache['key']) { $this->cache['key'] = md5($tSql . ($tArgs ? join(',', $tArgs) : '')); } if (false !== ($tData = $tMem->get($this->cache['key']))) { return $tData; } } # 查询数据库 $this->db =& self::instance($this->_config); if ($tArgs) { $tQuery = $this->db->prepare($tSql); $tQuery->execute($tArgs); } else { $tQuery = $this->db->query($tSql); } if (!$tQuery) { $this->error = $this->db->errorInfo(); isset($this->error[1]) || ($this->error = array()); return array(); } # 不缓存查询结果 if (!$this->cache) { return $tQuery->fetchAll(PDO::FETCH_ASSOC); } # 设置缓存 $tData = $tQuery->fetchAll(PDO::FETCH_ASSOC); $tMem->set($this->cache['key'], $tData, 0, $this->cache['expire']); $this->cache = array(); return $tData; }
$ctl_class = !empty($crl) ? ucfirst($res) . '_' . ucfirst($priv) . '_' . ucfirst($crl) : ucfirst($res) . '_' . ucfirst($priv); Loader::loadClass($ctl_class); if (($_SERVER['REQUEST_URI'] == '/' && (empty($testRes) && empty($testPriv)) || strpos($_SERVER['REQUEST_URI'], ".")) && class_exists($ctl_class, false)) { $ctl_obj = new $ctl_class(); isset($g_timer) && $g_timer->setMarker('dust.main class instanced'); // TODO: cache process $cached = checkCached($res, $priv, $crl, $request->format); if (is_array($cached) && isset($cached['life']) && isset($cached['cache_key'])) { $cache_life = $cached['life']; $cache_key = $cached['cache_key']; } else { $cache_life = intval($cached); $cache_key = sprintf("huitong_www_ac_%u_%s", crc32($_SERVER['REQUEST_URI']), $request->format); } if (!$request->isPost() && $cache_life > 0) { $cache = Cache_Memcache::getInstance(); $result = $cache->get($cache_key); if (FALSE === $result) { $result = $ctl_obj->execute($request); $cache->set($cache_key, $result, $cache_life); } } else { $result = $ctl_obj->execute($request); } isset($g_timer) && $g_timer->setMarker('dust.main class executed'); if ($result === TRUE) { $result = array('success' => true); } elseif (is_array($result) && count($result) == 3 && isset($result[0]) && isset($result[1]) && is_bool($result[0]) && is_string($result[1])) { $tmp = $result; if ($tmp[0] === TRUE) { $result = array('success' => true);
<?php require_once 'Cache/Memcache.php'; // Instantiate our Cache $cache = new Cache_Memcache(); // Use the REQUEST_URI as a key $key = $_SERVER['REQUEST_URI']; // Try to get our data $data = $cache->get($key, 'blog-pages'); // If the data is not false, we got something valid if ($data !== false) { echo $data; } else { // Generate data, you can do this with buffering: // Start the buffer ob_start(); // output all the data to the buffer // ... // Retrieve and output the data at the same time $data = ob_get_flush(); // Add it to the cache. $cache->set($key, $data, 'blog-pages'); }