本文整理汇总了PHP中Cache::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::factory方法的具体用法?PHP Cache::factory怎么用?PHP Cache::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* Returns a singleton instance
*
* @return Cache_Redis
* @access public
*/
public static function &getInstance()
{
if (!isset(self::$_instances[0]) || !self::$_instances[0]) {
self::$_instances[0] = Cache::factory('redis');
}
return self::$_instances[0];
}
示例2: action_cache
/**
* 缓存
*+----
*/
public function action_cache()
{
$cache = Cache::factory('file');
//获取一个文件缓存实例
//$cache->set('name', time(), 60); //设置有效期60s
echo $cache->get('name');
//$cache->del('name');
}
示例3: run
public function run(FilterChain $oFilterChain)
{
$aDb = Core::app()->config()->getCache();
foreach ($aDb as $k => $val) {
Manager::getInstance()->getCache()->add(Cache::factory($val['Driver'], $val['Params']), $k);
}
$oFilterChain->next();
}
示例4: __construct
/**
* Contrutor da classe
* @param string $url url acessada pelo usuário
*/
public function __construct($url)
{
define('CACHE_TIME', 60);
$cache_config = Config::get('cache');
if ($cache_config['page']) {
$cache = Cache::factory();
if ($cache->has(URL)) {
$data = $cache->read(URL);
exit($data);
}
}
$registry = Registry::getInstance();
$this->args = $this->args($url);
//I18n
define('lang', $this->args['lang']);
define('LANG', $this->args['lang']);
$i18n = I18n::getInstance();
$i18n->setLang(LANG);
$registry->set('I18n', $i18n);
function __($string, $format = null)
{
return I18n::getInstance()->get($string, $format);
}
function _e($string, $format = null)
{
echo I18n::getInstance()->get($string, $format);
}
define('controller', Inflector::camelize($this->args['controller']) . 'Controller');
define('action', str_replace('-', '_', $this->args['action']));
define('CONTROLLER', Inflector::camelize($this->args['controller']) . 'Controller');
define('ACTION', str_replace('-', '_', $this->args['action']));
try {
header('Content-type: text/html; charset=' . Config::get('charset'));
Import::core('Controller', 'Template', 'Annotation');
Import::controller(CONTROLLER);
$this->controller();
$this->auth();
$tpl = new Template();
$registry->set('Template', $tpl);
$tpl->render($this->args);
if ($cache_config['page']) {
$cache = Cache::factory();
$data = ob_get_clean();
$cache->write(URL, $data, $cache_config['time']);
}
Debug::show();
} catch (PageNotFoundException $e) {
header('HTTP/1.1 404 Not Found');
$this->loadError($e);
exit;
} catch (Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
$this->loadError($e);
}
}
示例5: array
/**
* @param string имя драйвера кеша
* @param mixed false или array()
* @return Cache объект
*/
static function &singleton($driver = 'apc', $init = true)
{
static $instances = array();
$signature = serialize(array($driver, $init));
if (empty($instances[$signature])) {
$instances[$signature] = Cache::factory($driver);
if ($init !== false) {
$instances[$signature]->init($init);
}
}
return $instances[$signature];
}
示例6: load_domain
static function load_domain($domain)
{
if (!isset(self::$items[$domain])) {
$cache = Cache::factory();
$locale = self::$locale;
$cache_key = "i18n/{$locale}/{$domain}";
$lang = Config::get('debug.i18n_nocache') ? false : $cache->get($cache_key);
if ($lang === false) {
$lang = array();
foreach (array_reverse(Core::file_paths(I18N_BASE . $locale . EXT, $domain)) as $path) {
!file_exists($path) or @(include $path);
}
$cache->set($cache_key, $lang);
}
self::$items[$domain] = (array) $lang;
}
}
示例7: getProperties
$key = 'Trilado.Annotation.Property.' . $this->classname . '->' . $property;
$cache = Cache::factory();
if (Debug::enabled() && $cache->has($key)) {
return $cache->read($key);
} else {
$reflection = new ReflectionProperty($this->classname, $property);
$comment = $reflection->getDocComment();
$annotation = $this->extractAnnotation($comment);
$cache->write($key, $annotation, CACHE_TIME);
return $annotation;
}
}
/**
* Pega a anotação todas as propriedades da classe
* @return array lista com instâncias de sdtClass
*/
public function getProperties()
{
示例8: parse
function parse()
{
if (!$this->_is_parsed) {
$cache_data = false;
$cache_key = Misc::key('Q:', $this->selector);
$cache = Cache::factory();
if (!Config::get('debug.Q_nocache', FALSE)) {
$cache_data = $cache->get($cache_key);
}
if (false === $cache_data) {
$query = $this->parse_selector();
$cache_data = array('name' => $query->name, 'SQL' => $query->SQL, 'count_SQL' => $query->count_SQL, 'sum_SQL' => $query->sum_SQL);
if ($cache) {
$cache->set($cache_key, $cache_data);
}
}
$this->SQL = $cache_data['SQL'];
$this->count_SQL = $cache_data['count_SQL'];
$this->sum_SQL = $cache_data['sum_SQL'];
$this->_is_parsed = TRUE;
$this->name = $cache_data['name'];
}
}
示例9: load
/**
* Carrega um arquivo de tradução pegando as mensagens e traduções e joga em array retornando-o
* @param string $lang nome do arquivo
* @throws TriladoException disparada caso o arquivo não exista ou o conteúdo esteja vazio
* @return array retorna um array com as mensagens de tradução, sendo as chaves o MD5 da mensagem original
*/
private function load($lang)
{
$key = 'Trilado.I18n.' . $lang;
$cache = Cache::factory();
if ($cache->has($key)) {
return $cache->read($key);
}
$file_path = ROOT . 'app/i18n/' . $lang . '.lang';
if (!file_exists($file_path)) {
throw new FileNotFoundException($file_path);
}
$lines = file($file_path);
if (!count($lines)) {
throw new TriladoException('Arquivo "' . $file_path . '" está vazio');
}
$key = false;
$result = array();
foreach ($lines as $line) {
$line = trim($line);
if (preg_match('@^(msgid|msgstr)@', $line)) {
if (preg_match('/^msgid "(.+)"/', $line, $match)) {
$key = md5($match[1]);
} elseif (preg_match('/^msgstr "(.+)"/', $line, $match)) {
if (!$key) {
throw new TriladoException('Erro de sintax no arquivo "' . $file_path . '" na linha "' . $match[1] . '"');
}
$result[$key] = $match[1];
$key = false;
}
}
}
foreach ($this->hook as $hook) {
$result = $hook->load($result);
}
$cache->write($key, $result, CACHE_TIME);
return $result;
}
示例10: getCache
public function getCache($which)
{
// do we already have the cache object in the Registry ?
if (Registry::isRegistered('cache_' . $which)) {
return Registry::get('cache_' . $which);
} else {
// get the config for our cache object
$config = Registry::get('config');
if (isset($config->cache->{$which}->handler)) {
$cache = Cache::factory($config->cache->{$which}->handler, isset($config->cache->{$which}->params) ? $config->cache->{$which}->params : array(), isset($config->cache->{$which}->lifetime) ? $config->cache->{$which}->lifetime : Cache::DEFAULT_LIFETIME);
return $cache;
} else {
throw new Exception('The cache handler "' . $which . '" is not set in config file');
}
}
}
示例11: define
define('CACHE_EXIT_ON_ERROR', true);
error_reporting(E_ALL);
// number of iterations
define('TEST_ITERATIONS', 100);
// how many reads should be performed per each set/update
define('TEST_READS', 1);
require "Benchmark/Timer.php";
require 'testCases/Cache.php';
$t = new Benchmark_Timer();
$t->start();
$aTests = array(25, 50, 75, 100);
$t->setMarker('Script init');
foreach ($aTests as $concurrency) {
$oTest = Cache::factory(array('type' => 'memcached', 'host' => '127.0.0.1', 'port' => 11211));
test_update($oTest, $concurrency, $t, 'MEMCACHED ');
$oTest = Cache::factory(array('type' => 'sharedance', 'host' => 'localhost'));
test_update($oTest, $concurrency, $t, 'SHAREDANCE');
}
$t->stop();
$t->display();
exit;
function test_update($oTest, $concurrency, $t, $text)
{
$oTest->disconnect();
$oTest->invalidateAll();
$oTest->init($concurrency, TEST_ITERATIONS);
for ($c = 0; $c < $concurrency; $c++) {
mt_srand(1000 + $c);
$pid = pcntl_fork();
if ($pid == 0) {
$oTest->connect();
示例12: __construct
/**
* Конструктор
*/
public function __construct($config)
{
parent::__construct($config);
hook('preload', array($this, 'hookPreload'));
$this->object(Cache::factory('normal', config('cache')));
}
示例13: loadDefaultLibs
/**
* Loads the default most commonly used libraries for the framework
*
* @return object
*/
public function loadDefaultLibs()
{
$config = Registry::get('config');
foreach ($this->defaultLibs as $library) {
if ($library == 'cache') {
try {
$cache = Cache::factory($config->get('cache/type'));
} catch (Config_KeyNoExist $e) {
// Revert to file based caching.
$cache = Cache::factory('file');
}
try {
$cache->ttl($config->get('cache/ttl'));
} catch (Exception $e) {
}
} else {
if ($library == 'i18n') {
try {
I18n::factory($config->get('locale/engine'));
} catch (Config_KeyNoExist $e) {
I18n::factory('failsafe');
}
} else {
$this->loadLib($library);
}
}
}
return $this;
}
示例14: autoload
/**
* Função que importa classes automaticamente, baseado nos diretórios
* registrados pelo método Import::register($dir).
* @param string $class Nome da classe a ser carregada.
* @return void
*/
public static function autoload($class)
{
$key = 'Trilado.Import.Files';
$cache = Cache::factory();
if ($cache->has($key)) {
$files = $cache->read($key);
if (isset($files[$class])) {
require_once $files[$class];
return;
}
}
foreach (self::$directories as $dir) {
$file = ROOT . $dir . $class . '.php';
if (file_exists($file)) {
require_once $file;
$files = $cache->read($key);
if ($files === false) {
$files = array();
}
$files[$class] = $file;
$cache->write($key, $files, CACHE_TIME);
return;
}
}
}
示例15: getUser
/**
* 获取用户信息
*
* @param int $userid 用户 id
* @param array $column 列
*/
public static function getUser($userid, $column = array())
{
$ret = array('id', 'userid', 'pwd', 'kid', 'mobile', 'email', 'status', 'regtime', 'regip', 'logintime', 'loginip', 'login_nums');
$ret = array_merge($ret, $column);
/*$select = Da_Wrapper::select()
->table(self::DB_TABLE_USER)
->columns($ret)
->where('id', $userid);
return $select->getRow();*/
$cache = Cache::factory();
$key = 'user_' . $userid;
$cacheData = $cache->get($key);
if (false == $cacheData) {
$select = Da_Wrapper::select()->table(self::DB_TABLE_USER)->where('id', $userid)->getRow();
$cache->set($key, $select);
} else {
$select = $cacheData;
}
foreach ($select as $key => $value) {
if (false == in_array($key, $ret)) {
unset($select[$key]);
}
}
return $select;
}