本文整理汇总了PHP中Timber::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Timber::cache方法的具体用法?PHP Timber::cache怎么用?PHP Timber::cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timber
的用法示例。
在下文中一共展示了Timber::cache方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* Apply global Timber customizations
*/
function timber_customizations()
{
// Early exit if Timber is not installed
if (!class_exists('Timber')) {
return;
}
global $wp_customize;
if (!Maera()->dev->dev_mode()) {
// Turn on Timber caching.
// See https://github.com/jarednova/timber/wiki/Performance#cache-the-twig-file-but-not-the-data
// This is a bit buggy right now on some hosts so we're disabling it.
// Timber::$cache = true;
$this->cache_mode();
} else {
TimberLoader::CACHE_NONE;
Timber::$cache = false;
$_SERVER['QUICK_CACHE_ALLOWED'] = FALSE;
Maera_Helper::define('DONOTCACHEPAGE', TRUE);
}
}
示例2: init
/**
* @see AbstractTheme::init()
*/
protected function init()
{
parent::init();
$gantry = Gantry::instance();
$global = $gantry['global'];
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
// Set lookup locations for Timber.
\Timber::$locations = $locator->findResources('gantry-engine://views');
// Enable caching in Timber.
\Timber::$twig_cache = true;
\Timber::$cache = false;
// Set autoescape in Timber.
\Timber::$autoescape = false;
add_theme_support('html5', ['comment-list', 'comment-form', 'search-form', 'gallery', 'caption', 'widgets']);
add_theme_support('title-tag');
add_theme_support('post-formats');
add_theme_support('post-thumbnails');
add_theme_support('menus');
add_theme_support('widgets');
add_theme_support('woocommerce');
add_filter('script_loader_tag', ['Gantry\\Framework\\Document', 'script_add_attributes'], 10, 2);
add_filter('timber_context', [$this, 'getContext']);
add_filter('timber/loader/twig', [$this, 'timber_loader_twig']);
add_filter('timber/cache/location', [$this, 'timber_cache_location']);
add_filter('get_twig', [$this, 'extendTwig'], 100);
add_filter('the_content', [$this, 'url_filter'], 0);
add_filter('the_excerpt', [$this, 'url_filter'], 0);
add_filter('widget_text', [$this, 'url_filter'], 0);
add_filter('widget_content', [$this, 'url_filter'], 0);
add_filter('widget_text', 'do_shortcode');
add_filter('widget_content', 'do_shortcode');
add_filter('widget_update_callback', ['\\Gantry\\WordPress\\Widgets', 'widgetCustomClassesUpdate'], 10, 4);
add_filter('dynamic_sidebar_params', ['\\Gantry\\WordPress\\Widgets', 'widgetCustomClassesSidebarParams'], 9);
add_action('template_redirect', [$this, 'set_template_layout'], -10000);
add_action('init', [$this, 'register_post_types']);
add_action('init', [$this, 'register_taxonomies']);
add_action('init', [$this, 'register_menus']);
add_action('template_redirect', [$this, 'disable_wpautop'], 10000);
add_action('widgets_init', [$this, 'widgets_init']);
add_action('wp_enqueue_scripts', [$this, 'prepare_particles'], 15);
add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts'], 20);
add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts'], 20);
add_action('wp_head', [$this, 'print_styles'], 20);
add_action('wp_head', [$this, 'print_scripts'], 30);
add_action('admin_print_styles', [$this, 'print_styles'], 200);
add_action('admin_print_scripts', [$this, 'print_scripts'], 200);
add_action('wp_footer', [$this, 'print_inline_scripts'], 100);
add_action('in_widget_form', ['\\Gantry\\WordPress\\Widgets', 'widgetCustomClassesForm'], 10, 3);
add_action('widgets_init', function () {
register_widget('\\Gantry\\WordPress\\Widget\\Particle');
});
add_shortcode('loadposition', [$this, 'loadposition_shortcode']);
// Offline support.
add_action('init', function () use($gantry, $global) {
if ($global->get('offline')) {
if (!(is_super_admin() || current_user_can('manage_options') || $_GLOBALS['pagenow'] == 'wp-login.php')) {
if (locate_template(['offline.php'])) {
add_filter('template_include', function () {
return locate_template(['offline.php']);
});
} else {
wp_die($global->get('offline_message'), get_bloginfo('title'));
}
} else {
$gantry['messages']->add(__('Site is currently in offline mode.', 'gantry5'), 'warning');
}
}
});
$this->preset_styles_init();
// Load theme text domains
$domain = $this->details()->get('configuration.theme.textdomain', $this->name);
load_theme_textdomain($domain, $this->path . '/languages');
$this->url = $gantry['site']->theme->link;
}
示例3: testWPCLIClearCacheAllArray
function testWPCLIClearCacheAllArray()
{
$cache_dir = __DIR__ . '/../cache/twig';
if (is_dir($cache_dir)) {
TimberLoader::rrmdir($cache_dir);
}
$this->assertFileNotExists($cache_dir);
Timber::$cache = true;
$pid = $this->factory->post->create();
$post = new TimberPost($pid);
Timber::compile('assets/single-post.twig', array('post' => $post));
sleep(1);
$this->assertFileExists($cache_dir);
Timber::compile('assets/single.twig', array('data' => 'foobar'), 600);
$success = TimberCommand::clear_cache(array('all'));
$this->assertTrue($success);
Timber::$cache = false;
$success = TimberCommand::clear_cache('bunk');
$this->assertNull($success);
}
示例4: testTwigCache
function testTwigCache()
{
$cache_dir = __DIR__ . '/../cache/twig';
if (is_dir($cache_dir)) {
TimberLoader::rrmdir($cache_dir);
}
$this->assertFileNotExists($cache_dir);
Timber::$cache = true;
$pid = $this->factory->post->create();
$post = new TimberPost($pid);
Timber::compile('assets/single-post.twig', array('post' => $post));
sleep(1);
$this->assertFileExists($cache_dir);
Timber::$cache = false;
$loader = new TimberLoader();
$loader->clear_cache_twig();
$this->assertFileNotExists($cache_dir);
}