本文整理汇总了PHP中Environment::getCache方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::getCache方法的具体用法?PHP Environment::getCache怎么用?PHP Environment::getCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::getCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onStatusChange
public function onStatusChange($new_status)
{
if ($new_status == 'disabled') {
$cache = Environment::getCache('modules.GalleryModule');
$cache->clean(array(Cache::ALL => TRUE));
}
}
示例2: load
/**
* merges config files of each module imported via config.ini[modules] to one file and loads it
* considering current environment [dev, production, ...] - separate config file for each
* uses Nette/Cache for invalidation when one (or more) of config files changed
*
* @param string|null filepath
* @return Config
*/
public static function load($baseConfigFile = null)
{
if ($baseConfigFile === null) {
$baseConfigFile = Environment::expand(Environment::getConfigurator()->defaultConfigFile);
}
$envName = Environment::getName();
Environment::setVariable('tempDir', VAR_DIR . '/cache');
$cache = Environment::getCache('config');
$key = "config[{$envName}]";
if (!isset($cache[$key])) {
// najviac casu zabera load, tak az tu, ked ho je treba
$appConfig = Environment::loadConfig($baseConfigFile);
$configs = array(Config::fromFile($baseConfigFile, $envName)->toArray());
$configPaths = array($baseConfigFile);
foreach ($appConfig->modules as $c) {
$configPaths[] = $path = MODULES_DIR . "/{$c}Module/config.ini";
if (file_exists($path)) {
$configs[] = Config::fromFile($path, $envName)->toArray();
}
}
$arrayConfig = call_user_func_array('array_merge_recursive', $configs);
$cache->save($key, $arrayConfig, array('files' => $configPaths));
}
return Environment::loadConfig(new Config($cache[$key]));
}
示例3: invalidateCache
public static function invalidateCache($type = NULL)
{
if (is_null($type)) {
$type = static::$cacheKey;
}
$cache = Environment::getCache("Seolinks." . $type);
unset($cache['data']);
}
示例4: invalidate
/**
* invalidate cache by type (and section) and/or tags
*
* @param string|null
* @param string|null
* @param string
*
* @return void
*/
public static function invalidate($type = null, $tags = null, $section = 'data')
{
if ($type) {
$cache = Environment::getCache($type);
unset($cache[$section]);
}
// expire by given tags
if ($tags) {
$cache = Environment::getCache();
$cache->clean(array('tags' => array($tags)));
}
}
示例5: setOwnerId
public function setOwnerId($id)
{
if (defined('ACL_CACHING') and ACL_CACHING) {
$this->cache = Environment::getCache();
$key = static::ID . '-' . $id;
if (!isset($this->cache[$key])) {
$this->cache->save($key, static::getDependencies($id));
}
$this->ownerId = $this->cache[$key];
} else {
$this->ownerId = static::getDependencies($id);
}
}
示例6: render
/**
* Renders template to output.
* @return void
*/
public function render()
{
$cache = Environment::getCache('StringTemplate');
$key = md5($this->content);
$content = $cache[$key];
if ($content === NULL) {
// not cached
if (!$this->getFilters()) {
$this->onPrepareFilters($this);
}
$cache[$key] = $content = $this->compile($this->content);
}
$this->__set('template', $this);
/*Nette\Loaders\*/
LimitedScope::evaluate($content, $this->getParams());
}
示例7: run
public function run()
{
$this->cache = Environment::getCache('Application');
$modules = Environment::getConfig('modules');
if (!empty($modules)) {
foreach ($modules as $module) {
$this->loadModule($module);
}
}
$this->setupRouter();
// $this->setupHooks();
// Requires database connection
$this->onRequest[] = array($this, 'setupPermission');
// ...
// Run the application!
parent::run();
$this->cache->release();
}
示例8: getPanel
/**
* Renders HTML code for custom panel.
* @return void
*/
function getPanel()
{
//Debug::timer('presenter-tree');
$cache = Environment::getCache('debug/panels/PresenterTree');
if (isset($cache['tree'])) {
$tree = $cache['tree'];
} else {
Environment::enterCriticalSection('debug/panels/PresenterTree');
$generated = $this->generate();
$tree = $cache->save('tree', $generated['tree'], array('files' => $generated['depends']));
Environment::leaveCriticalSection('debug/panels/PresenterTree');
}
ob_start();
$template = new Template(dirname(__FILE__) . '/bar.presentertree.panel.phtml');
$template->tree = $tree;
$template->render();
//Debug::fireLog('presenter-tree render time (ms): ' . round(1000 * Debug::timer('presenter-tree', TRUE), 2));
return $cache['output'] = ob_get_clean();
}
示例9: factory
/**
* Autoloader factory.
* @return Acl
*/
public static function factory()
{
$expire = 24 * 60 * 60;
// 1 den
$driver = Environment::getConfig('database')->driver;
try {
$key = 'acl';
$cache = Environment::getCache('application/acl');
if (isset($cache[$key])) {
// serving from cache
return $cache[$key];
} else {
$acl = new self();
$cache->save($key, $acl, array('expire' => $expire, 'tags' => array('system', 'acl')));
return $acl;
}
} catch (Exception $e) {
$acl = new self();
//$cache->save($key, $acl, array('expire' => $expire));
return $acl;
}
}
示例10: startup
public function startup()
{
parent::startup();
if (!isset($this->lang)) {
$this->lang = $this->getHttpRequest()->detectLanguage($this->langs);
if ($this->lang == null) {
$this->lang = 'en';
}
$this->canonicalize();
}
$this->translator = Environment::getService('Mokuji\\Translator\\Admin');
$this->translator->lang = $this->lang;
//$this->translator = new Admin_Translator($this->lang);
$cache = Environment::getCache('langs');
$langs = $cache->offsetGet('langs');
if ($langs == NULL) {
$this->langs = $this->translator->getSupportedLangs();
//$this->model('lang')->getAll();
$cache->save('langs', $this->langs);
} else {
$this->langs = $langs;
}
$this->refreshConfig();
}
示例11: getCache
/**
* @return Cache
*/
protected function getCache()
{
return Environment::getCache('Nette.RobotLoader');
}
示例12: changeStatus
public static function changeStatus($module_name, $new_status)
{
Admin_ModulesModel::changeStatus($module_name, $new_status);
$cache = Environment::getCache('modules.' . $module_name . 'Module');
$cache->save('status', $new_status);
}
示例13: getCache
/**
* @return Cache
*/
protected static function getCache()
{
return Environment::getCache('Nette.Annotations');
}
示例14: getCache
/**
* Getter for Cache instance
* Creates instance if called for the first time
* Creates MemcachedStorage if extension memcache exists
* Otherwise FileStorage Cache is created
* Triggers notice if config variable advertisememcached in perform block is not set to false
* @return Cache
*/
public static function getCache()
{
if (!self::$cache) {
$config = Environment::getConfig('perform');
if (extension_loaded('memcache')) {
self::$cache = new Cache(new MemcachedStorage($config->memcache_host, $config->memcache_port, $config->cache_prefix));
$namespace = self::$cache;
$namespace['test'] = true;
if ($namespace['test'] === true) {
return self::$cache;
}
}
self::$cache = Environment::getCache($config->cache_prefix);
if ($config->advertisememcached) {
trigger_error("FileCache enabled, use Memcached if possible. Turn off this warning by setting advertisememcached to false", E_USER_WARNING);
}
}
return self::$cache;
}
示例15: foreach
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tmpDir), RecursiveIteratorIterator::CHILD_FIRST) as $entry) {
// delete all files
if ($entry->isDir()) {
@rmdir($entry);
} else {
@unlink($entry);
}
}
Environment::setVariable('tempDir', $tmpDir);
$key = '';
$value = array();
for ($i = 0; $i < 32; $i++) {
$key .= chr($i);
$value[] = chr($i) . chr(255 - $i);
}
$cache = Environment::getCache();
echo "Is cached?\n";
Debug::dump(isset($cache[$key]));
echo "Cache content:\n";
Debug::dump($cache[$key]);
echo "Writing cache...\n";
$cache[$key] = $value;
$cache->release();
echo "Is cached?\n";
Debug::dump(isset($cache[$key]));
echo "Is cache ok?\n";
Debug::dump($cache[$key] === $value);
echo "Removing from cache using unset()...\n";
unset($cache[$key]);
$cache->release();
echo "Is cached?\n";