symfony2 : How to disable APC cache selectively on few routes

标签 symfony caching apc

我使用的是 symfony 版本 2.3 。我在 config.yml 中使用了以下内容

metadata_cache_driver: apc
result_cache_driver: apc
query_cache_driver: apc

我想禁用以下 URL 的缓存。 www.domain.com/dashboard

我怎样才能实现这个目标?任何帮助

最佳答案

在您的 app.phpindex.php 中,您应该有这样的内容:

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
$apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);

require_once __DIR__.'/../app/AppKernel.php';
require_once __DIR__.'/../app/AppCache.php';

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel = new AppCache($kernel);

// ...

因此您可以使用 $_SERVER['REQUEST_URI']

设定条件

例如

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();

if (!preg_match('#dashboard#'), $_SERVER['REQUEST_URI']) {
    $apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
    $loader->unregister();
    $apcLoader->register(true);

    require_once __DIR__.'/../app/AppCache.php';

    $kernel = new AppCache($kernel);
}

// ...

希望对你有帮助

关于symfony2 : How to disable APC cache selectively on few routes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30010375/

相关文章:

Symfony 表单标签渲染

php - 如何在使用 Symfony2 保存之前设置或更改实体值

symfony - 变量.yml 中的翻译

apache - Symfony 3.1 : error when requesting app_dev. php 或 app.php

java - Hibernate二级缓存问题

php - 什么可能将 "Pragma:no-cache"添加到我的响应 header 中? ( Apache ,PHP)

php - 脚本头/信号 11 过早结束

php - 如何找到 apc.php 文件位置?

google-app-engine - 更新 AppEngine 中每个实例的内存缓存(自动扩展)

PHP APC 和 Imagick 与 cpanel