本文整理汇总了PHP中Cache::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::cache方法的具体用法?PHP Cache::cache怎么用?PHP Cache::cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::cache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCache
static function getCache()
{
if (!self::$cache) {
$config = getConfiguration('cache');
// apply any overides to the configuration
self::$compression = array_val($config, 'compression', self::$compression);
self::$default_ttl = array_val($config, 'default_ttl', self::$default_ttl);
self::$connect_timeout_msec = array_val($config, 'connect_timeout_msec', self::$connect_timeout_msec);
self::$cache_enabled = array_val($config, 'cache_enabled', self::$cache_enabled);
self::$local_cache_enabled = array_val($config, 'local_cache_enabled', self::$local_cache_enabled);
// apply any overides to the debug mode
self::$debug = array_val($config, 'debug', self::$debug);
self::$local_cache_debug = array_val($config, 'local_cache_debug', self::$local_cache_debug);
// build the cache object and connect the servers
self::$cache = new Memcache();
// get the server list out of the configuration
foreach (array_val($config, 'servers') as $machine_name) {
// load the configuration block for each server
$server_config = getConfiguration('cache', $machine_name);
// setup this servers connection
self::$cache->addServer($server_config['host'], $server_config['port'], false, $server_config['weight'], 1, 1, false, null);
//, self::$connect_timeout_msec);
}
}
return self::$cache;
}
示例2: __construct
/**
* Prohibit creating an object from outside
*/
public function __construct()
{
phpFastCache::setup("storage", "files");
phpFastCache::setup("path", FRONTEND_PATH . "../" . self::PATH);
phpFastCache::setup("securityKey", "cache");
self::$cache = new phpFastCache();
}
示例3: init
public static function init()
{
if (Config::config('cache') == true) {
$config = Config::cache();
Loader::core('CacheCarry');
Loader::driver('caches', $config['driver']);
self::$cache = new $config['driver']($config);
}
}
示例4: display
/**
* The display method that including caching.
*
* @return string
* @author Justin Palmer
**/
public function display()
{
//var_dump($this->Controller);
//If the cache type is null just return the template.
//Or, if the cache_type is not one of the supported cache_types
if ($this->view_path === null || !$this->Controller->pr_do_cache || !$this->isValidCacheType()) {
return parent::display();
}
//If it is a valid cache type then call the method and return the template view.
$cached = $this->Cache->isCached();
if ($cached !== false) {
return $this->Cache->get();
} else {
$content = parent::display();
$this->Cache->value = $content;
$this->Cache->cache();
return $content;
}
}
示例5: init
private static function init()
{
if (self::$cache !== null) {
return;
}
global $global;
self::$prefix = $global['name'] . '_';
self::$cache = new Memcache();
self::$cache->pconnect('127.0.0.1', 11211);
}
示例6: init
public static function init()
{
global $config;
switch ($config['cache']['enabled']) {
case 'memcached':
self::$cache = new Memcached();
self::$cache->addServers($config['cache']['memcached']);
break;
case 'php':
self::$cache = array();
break;
}
}
示例7: getCache
/**
* This method obtain the cache if neccesary and return it
*
* @access public
* @static
* @return array The cache of the SVG file
* @throws Exception If the cache isn't defined an exception is throwed
*/
public static function getCache()
{
self::init();
if (file_exists(self::$filename) === false) {
return array();
}
include self::$filename;
if (isset($cache) === false) {
throw new Exception('The cache isn\'t defined!');
}
self::$cache = $cache;
return $cache;
}
示例8: Memcache
function __construct()
{
$host = Config::get('db_host');
$user = Config::get('db_user');
$pass = Config::get('db_pass');
$database = Config::get('db_database');
$this->dbConnection = Database::connect($host, $user, $pass, $database);
if (Config::get('memcache_enabled')) {
$this->memcacheConnection = new Memcache();
$this->memcacheConnection->pconnect(Config::get('memcache_host'), Config::get('memcache_port'));
Cache::$cache = $this->memcacheConnection;
Cache::$prefix = Config::get('memcache_prefix');
}
}
示例9: parse
public function parse()
{
if (!file_exists($this->file)) {
throw new NotFound("Template {$this->file} does not exist");
}
if ($this->load_from_cache) {
$oCache = new Cache($this->tpl);
if ($oCache->isValid()) {
return $oCache->load();
} else {
$content = $this->readTemplate();
$oCache->cache($content);
return $content;
}
}
return $this->readTemplate();
}
示例10: flush
public static function flush()
{
global $config;
switch ($config['cache']['enabled']) {
case 'memcached':
if (!self::$cache) {
self::init();
}
return self::$cache->flush();
case 'apc':
return apc_clear_cache('user');
case 'php':
self::$cache = array();
break;
case 'fs':
$files = glob('tmp/cache/*');
foreach ($files as $file) {
unlink($file);
}
break;
case 'redis':
if (!self::$cache) {
self::init();
}
return self::$cache->flushDB();
}
return false;
}
示例11: clearExpired
/**
* Clear expired cache data via Cron module.
*/
public static function clearExpired()
{
Cache::cache()->where('expires_on', '<=', time())->delete();
}
示例12: __construct
/**
* Prohibit creating an object from outside
*/
public function __construct()
{
phpFastCache::setup("storage", "files");
self::$cache = new phpFastCache();
}
示例13: foreach
<?php
define('OC_CACHE_HOST', '127.0.0.1');
define('OC_CACHE_PORT', '11211');
define('OC_TMP', 'TMP');
define('OC_LAST_ADD_VM', 'lastAddVM');
define('OC_LAST_ADD_PM', 'lastAddPM');
define('OC_LAST_REM_VM', 'lastRemVM');
define('OC_LAST_REM_PM', 'lastRemPM');
define('OC_ND_HIGH_CONVERGENCE', true);
define('OC_STORE', 'classes');
$folders = ['src', 'src/basics', 'src/interfaces', 'src/helpers', 'src/model', 'src/rules', 'src/qualifiers', 'src/costs'];
foreach ($folders as $folder) {
foreach (glob("{$folder}/*.php") as $filename) {
require_once "{$filename}";
}
}
$cache = new Memcached();
$cache->addServer(OC_CACHE_HOST, OC_CACHE_PORT);
Cache::$cache = $cache;
require_once "tests/dummyClasses.php";
Counter::$start = time() - 1;
示例14: js
public function js($section, $revision)
{
$revision = explode('.', $revision);
$revision = (int) $revision[0];
$file = sprintf("%s.js", $section);
$cache = new Cache($file);
if ($cache->isValid($revision)) {
$content = $cache->load();
} else {
$content = '';
foreach ($this->js[$section] as $style) {
$content .= file_get_contents($style) . "\n";
}
$content = JSMin::minify($content);
$cache->cache($content);
}
$context = Context::getInstance();
$context->response->contentType = 'text/javascript';
$context->response->addHeader("Expires", gmdate('D, d M Y H:i:s', time() + 365 * 24 * 3600) . ' GMT');
return ETag::send($cache->cache_file);
}
示例15: setEngine
public static function setEngine(CacheEngine $cache)
{
self::$cache = $cache;
}