本文整理汇总了PHP中Cache::driver方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::driver方法的具体用法?PHP Cache::driver怎么用?PHP Cache::driver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::driver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: factory
/**
* Create a new session driver instance.
*
* @param string $driver
* @return Session\Drivers\Driver
*/
public static function factory($driver)
{
if (isset(static::$registrar[$driver])) {
$resolver = static::$registrar[$driver];
return $resolver();
}
switch ($driver) {
case 'apc':
return new Session\Drivers\APC(Cache::driver('apc'));
case 'cookie':
return new Session\Drivers\Cookie();
case 'database':
return new Session\Drivers\Database(Database::connection());
case 'file':
return new Session\Drivers\File(path('storage') . 'sessions' . DS);
case 'memcached':
return new Session\Drivers\Memcached(Cache::driver('memcached'));
case 'memory':
return new Session\Drivers\Memory();
case 'redis':
return new Session\Drivers\Redis(Cache::driver('redis'));
default:
throw new \Exception("Session driver [{$driver}] is not supported.");
}
}
示例2: zbase_cache_driver
/**
* Return the current cache driver
* @return string
*/
function zbase_cache_driver($store = null)
{
if (is_null($store)) {
return \Cache::driver();
}
return \Cache::store($store);
}
示例3: setDriver
/**
* Devuelve una instancia de cache del driver pasado
*
* @param array $params parametros nombrados
*/
private function setDriver($params)
{
if (isset($params['driver'])) {
return Cache::driver($params['driver']);
}
return Cache::driver();
}
示例4: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$cacheDriver = $this->option('driver');
$cacheName = $this->option('name');
if (\Cache::driver($cacheDriver)->has($cacheName)) {
$this->comment('Value: ' . \Cache::driver($cacheDriver)->get($cacheName));
\Cache::driver($cacheDriver)->forget($cacheName);
$this->info("{$cacheName} has been successfully removed from cache {$cacheDriver}");
} else {
$this->error("{$cacheName} is already cleared from cache {$cacheDriver}");
}
$this->info('Done!');
}
示例5: __construct
/**
* Constructor.
*
* @access protected
*/
protected function __construct()
{
$plugins_cache_id = '';
$plugin_manifest = [];
$plugin_settings = [];
// Get Plugins List
$plugins_list = Config::get('system.plugins');
// If Plugins List isnt empty then create plugin cache ID
if (is_array($plugins_list) && count($plugins_list) > 0) {
// Go through...
foreach ($plugins_list as $plugin) {
if (File::exists($_plugin = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
$plugins_cache_id .= filemtime($_plugin);
}
}
// Create Unique Cache ID for Plugins
$plugins_cache_id = md5('plugins' . ROOT_DIR . PLUGINS_PATH . $plugins_cache_id);
}
// Get plugins list from cache or scan plugins folder and create new plugins cache item
if (Cache::driver()->contains($plugins_cache_id)) {
Config::set('plugins', Cache::driver()->fetch($plugins_cache_id));
} else {
// If Plugins List isnt empty
if (is_array($plugins_list) && count($plugins_list) > 0) {
// Go through...
foreach ($plugins_list as $plugin) {
if (File::exists($_plugin_manifest = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
$plugin_manifest = Yaml::parseFile($_plugin_manifest);
}
if (File::exists($_plugin_settings = PLUGINS_PATH . '/' . $plugin . '/settings.yml')) {
$plugin_settings = Yaml::parseFile($_plugin_settings);
}
$_plugins_config[File::name($_plugin_manifest)] = array_merge($plugin_manifest, $plugin_settings);
}
Config::set('plugins', $_plugins_config);
Cache::driver()->save($plugins_cache_id, $_plugins_config);
}
}
// Include enabled plugins
if (is_array(Config::get('plugins')) && count(Config::get('plugins')) > 0) {
foreach (Config::get('plugins') as $plugin_name => $plugin) {
if (Config::get('plugins.' . $plugin_name . '.enabled')) {
include_once PLUGINS_PATH . '/' . $plugin_name . '/' . $plugin_name . '.php';
}
}
}
// Run Actions on plugins_loaded
Action::run('plugins_loaded');
}
示例6: get
/**
* Get Page Block
*
* <code>
* $block = Blocks::get('my-block');
* </code>
*
* @access public
* @param string $name Block name
* @return string Formatted Block content
*/
public static function get($name)
{
if (File::exists($block_path = STORAGE_PATH . '/blocks/' . $name . '.md')) {
// Create Unique Cache ID for Block
$block_cache_id = md5('block' . ROOT_DIR . $block_path . filemtime($block_path));
if (Cache::driver()->contains($block_cache_id)) {
return Cache::driver()->fetch($block_cache_id);
} else {
Cache::driver()->save($block_cache_id, $block = Filter::apply('content', file_get_contents($block_path)));
return $block;
}
} else {
return 'Block ' . $name . ' is not found!';
}
}
示例7: remove
/**
* Comando de consola para eliminar un elemento cacheado
*
* @param array $params parametros nombrados de la consola
* @param string $id id del elemento
* @param string $group nombre de grupo
* @throw KumbiaException
*/
public function remove($params, $id, $group = 'default')
{
// obtiene el driver de cache
if (isset($params['driver'])) {
$cache = Cache::driver($params['driver']);
} else {
$cache = Cache::driver();
}
// elimina el elemento
if ($cache->remove($id, $group)) {
echo '-> Se ha eliminado el elemento de la cache', PHP_EOL;
} else {
throw new KumbiaException("No se ha logrado eliminar el elemento \"{$id}\" del grupo \"{$group}\"");
}
}
示例8: factory
/**
* Template factory
*
* <code>
* $template = Template::factory('templates_path');
* </code>
*
* @param string|Fenom\ProviderInterface $source path to templates or custom provider
* @param string $compile_dir path to compiled files
* @param int|array $options
* @throws InvalidArgumentException
* @return Fenom
*/
public static function factory($source, $compile_dir = '/tmp', $options = 0)
{
// Create fenom cache directory if its not exists
!Dir::exists(CACHE_PATH . '/fenom/') and Dir::create(CACHE_PATH . '/fenom/');
// Create Unique Cache ID for Theme
$theme_config_file = THEMES_PATH . '/' . Config::get('system.theme') . '/' . Config::get('system.theme') . '.yml';
$theme_cache_id = md5('theme' . ROOT_DIR . $theme_config_file . filemtime($theme_config_file));
// Set current them options
if (Cache::driver()->contains($theme_cache_id)) {
Config::set('theme', Cache::driver()->fetch($theme_cache_id));
} else {
$theme_config = Yaml::parseFile($theme_config_file);
Config::set('theme', $theme_config);
Cache::driver()->save($theme_cache_id, $theme_config);
}
$compile_dir = CACHE_PATH . '/fenom/';
$options = Config::get('system.fenom');
$fenom = parent::factory($source, $compile_dir, $options);
$fenom->assign('config', Config::getConfig());
return $fenom;
}
示例9: getMetadata
/**
* Obtiene la metadata de la tabla
* Y la cachea si esta en producción
*
* @param string $type tipo de controlador
* @param string $database
* @param string $table
* @param string $schema
* @return Metadata
*/
private static function getMetadata($type, $database, $table, $schema)
{
if (PRODUCTION && !(self::$instances["{$database}.{$table}.{$schema}"] = \Cache::driver()->get("{$database}.{$table}.{$schema}", 'ActiveRecord.Metadata'))) {
return self::$instances["{$database}.{$table}.{$schema}"];
}
$class = ucwords($type) . 'Metadata';
$class = __NAMESPACE__ . "\\{$class}";
self::$instances["{$database}.{$table}.{$schema}"] = new $class($database, $table, $schema);
// Cachea los metadatos
if (PRODUCTION) {
\Cache::driver()->save(self::$instances["{$database}.{$table}.{$schema}"], \Config::get('config.application.metadata_lifetime'), "{$database}.{$table}.{$schema}", 'ActiveRecord.Metadata');
}
return self::$instances["{$database}.{$table}.{$schema}"];
}
示例10: d
function d($name, $value = '[get]', $expire = 0)
{
$instance = Cache::driver('mysql');
if (is_null($name)) {
//删除所有缓存
return $instance->flush();
}
switch ($value) {
case '[get]':
//获取
return $instance->get($name);
case '[del]':
//删除
return $instance->del($name);
case '[truncate]':
//删除所有缓存
return $instance->flush($name);
default:
return $instance->set($name, $value, $expire);
}
}
示例11: getDriver
public function getDriver($alias)
{
try {
if ($alias == "Auth") {
$driver = \Auth::driver();
} elseif ($alias == "DB") {
$driver = \DB::connection();
} elseif ($alias == "Cache") {
$driver = \Cache::driver();
} elseif ($alias == "Queue") {
$driver = \Queue::connection();
} else {
return false;
}
return get_class($driver);
} catch (\Exception $e) {
$this->error("Could not determine driver/connection for {$alias}.");
return false;
}
}
示例12: define
// Lee la configuracion
$config = Config::read('config');
// Constante que indica si la aplicacion se encuentra en produccion
if (!defined('PRODUCTION')) {
define('PRODUCTION', $config['application']['production']);
}
// Carga la cache y verifica si esta cacheado el template, al estar en produccion
if (PRODUCTION) {
// @see Cache
require CORE_PATH . 'libs/cache/cache.php';
//Asigna el driver por defecto usando el config.ini
if (isset($config['application']['cache_driver'])) {
Cache::setDefault($config['application']['cache_driver']);
}
// Verifica si esta cacheado el template
if ($template = Cache::driver()->get($url, 'kumbia.templates')) {
//verifica cache de template para la url
echo $template;
echo '<!-- Tiempo: ' . round(microtime(1) - START_TIME, 4) . ' seg. -->';
exit(0);
}
}
// Asignando locale
if (isset($config['application']['locale'])) {
setlocale(LC_ALL, $config['application']['locale']);
}
// Establecer el timezone para las fechas y horas
if (isset($config['application']['timezone'])) {
ini_set('date.timezone', $config['application']['timezone']);
}
// Establecer el charset de la app en la constante APP_CHARSET
示例13: getPage
/**
* Get page
*
* <code>
* $page = Pages::getPage('downloads');
* </code>
*
* @access public
* @param string $url Url
* @return array
*/
public static function getPage($url)
{
// If url is empty that its a homepage
if ($url) {
$file = STORAGE_PATH . '/pages/' . $url;
} else {
$file = STORAGE_PATH . '/pages/' . 'index';
}
// Select the file
if (is_dir($file)) {
$file = STORAGE_PATH . '/pages/' . $url . '/index.md';
} else {
$file .= '.md';
}
// Get 404 page if file not exists
if (!file_exists($file)) {
$file = STORAGE_PATH . '/pages/' . '404.md';
Response::status(404);
}
// Create Unique Cache ID for requested page
$page_cache_id = md5('page' . ROOT_DIR . $file . filemtime($file));
if (Cache::driver()->contains($page_cache_id) && Config::get('system.pages.flush_cache') == false) {
return Cache::driver()->fetch($page_cache_id);
} else {
$content = file_get_contents($file);
$_page = explode('---', $content, 3);
$page = Yaml::parse($_page[1]);
$url = str_replace(STORAGE_PATH . '/pages', Url::getBase(), $file);
$url = str_replace('index.md', '', $url);
$url = str_replace('.md', '', $url);
$url = str_replace('\\', '/', $url);
$url = rtrim($url, '/');
$page['url'] = $url;
$_content = $_page[2];
// Parse page for summary <!--more-->
if (($pos = strpos($_content, "<!--more-->")) === false) {
$_content = Filter::apply('content', $_content);
} else {
$_content = explode("<!--more-->", $_content);
$_content['summary'] = Filter::apply('content', $_content[0]);
$_content['content'] = Filter::apply('content', $_content[0] . $_content[1]);
}
if (is_array($_content)) {
$page['summary'] = $_content['summary'];
$page['content'] = $_content['content'];
} else {
$page['content'] = $_content;
}
$page['slug'] = basename($file, '.md');
// Overload page title, keywords and description if needed
empty($page['title']) and $page['title'] = Config::get('site.title');
empty($page['keywords']) and $page['keywords'] = Config::get('site.keywords');
empty($page['description']) and $page['description'] = Config::get('site.description');
Cache::driver()->save($page_cache_id, $page);
return $page;
}
}
示例14: set_meta_data
/**
* Crea un registro de meta datos para la tabla especificada
*
* @param string $table
* @param array $meta_data
*/
static function set_meta_data($table, $meta_data)
{
if (PRODUCTION) {
Cache::driver()->save(serialize($meta_data), Config::get('config.application.metadata_lifetime'), $table, 'kumbia.models');
}
self::$models[$table] = $meta_data;
return true;
}
示例15: partial
/**
* Renderiza una vista parcial
*
* @param string $partial vista a renderizar
* @param string $__time tiempo de cache
* @param array $params
* @param string $group grupo de cache
* @return string
* @throw KumbiaException
*/
public static function partial($partial, $__time = '', $params = NULL, $group = 'kumbia.partials')
{
if (PRODUCTION && $__time && !Cache::driver()->start($__time, $partial, $group)) {
return;
}
//Verificando el partials en el dir app
$__file = APP_PATH . "views/_shared/partials/{$partial}.phtml";
if (!is_file($__file)) {
//Verificando el partials en el dir core
$__file = CORE_PATH . "views/partials/{$partial}.phtml";
}
if ($params) {
if (is_string($params)) {
$params = Util::getParams(explode(',', $params));
}
// carga los parametros en el scope
extract($params, EXTR_OVERWRITE);
}
// carga la vista parcial
if (!(include $__file)) {
throw new KumbiaException('Vista Parcial "' . $__file . '" no se encontro');
}
// se guarda en la cache de ser requerido
if (PRODUCTION && $__time) {
Cache::driver()->end();
}
}