2016-04-07 18 views
0

私のすべてのページ(ログに記録された人のみ)から呼び出されるアクションがあります。このアクションは、自分のTwitterアカウントから最新のツイートを取得します。Symfony 2 ESIキャッシュ

私は次のように

を変更してきたキャッシュを有効にするには10分

public function socialAction(){ 

    $consumerKey = $this->container->getParameter('consumer_key'); 
    $consumerSecret = $this->container->getParameter('consumer_secret'); 
    $accessToken = $this->container->getParameter('access_token'); 
    $accessTokenSecret = $this->container->getParameter('access_token_secret'); 

    // on appel l'API 
    $tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); 
    $screen_name = "blabla"; 
    $tweets = $tweet->get('statuses/user_timeline', [ 
     'screen_name' => $screen_name, 
     'exclude_replies' => true, 
     'count' => 50 
    ]); 
    $tweets = array_splice($tweets, 0, 5); 

    $response = $this->render('GestionJeuBundle:Default:social.html.twig', array("tweets" => $tweets)); 

    $response->setPublic(); 
    $response->setSharedMaxAge(600); 

    return $response; 

}

のキャッシュにあるように、このアクションの結果をしたいと思いますので、APIへのアクセスが制限され

app/config/config.yml 

framework: 
    esi: { enabled: true } 
    fragments: { path: /_proxy } 

app/AppCache.php 


<?php 

require_once __DIR__.'/AppKernel.php'; 

use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache; 

class AppCache extends HttpCache 
{ 
    protected function getOptions() 
    { 
     return array(
      'debug'     => false, 
      'default_ttl'   => 0, 
      'private_headers'  => array('Authorization', 'Cookie'), 
      'allow_reload'   => false, 
      'allow_revalidate'  => false, 
      'stale_while_revalidate' => 2, 
      'stale_if_error'   => 60, 
     ); 
    } 
} 
012ページがすべてのページの更新を更新していることにもかかわらず

web/app_dev.php 

<?php 

use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\Debug\Debug; 

// If you don't want to setup permissions the proper way, just uncomment the following PHP line 
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information 
//umask(0000); 

// This check prevents access to debug front controllers that are deployed by accident to production servers. 
// Feel free to remove this, extend it, or make something more sophisticated. 
if (isset($_SERVER['HTTP_CLIENT_IP']) 
    || isset($_SERVER['HTTP_X_FORWARDED_FOR']) 
    || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '.....', 'fe80::1', '::1')) 
) { 
    header('HTTP/1.0 403 Forbidden'); 
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.'); 
} 

$loader = require_once __DIR__.'/../app/bootstrap.php.cache'; 
Debug::enable(); 

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

$kernel = new AppKernel('dev', true); 
$kernel->loadClassCache(); 
$kernel = new AppCache($kernel); 

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter 
Request::enableHttpMethodParameterOverride(); 
$request = Request::createFromGlobals(); 
$response = $kernel->handle($request); 
$response->send(); 

$kernel->terminate($request, $response); 
error_log($kernel->getLog()); 

(テストの後、それはあまりにもapp.phpに変更して、本番環境でまったく同じことを行います)

は私がAを誤解したり忘れてしまいましたもの?

ご協力いただきありがとうございます。

EDITは解決:私は、私の知る限り、最後の数週間実験として、私の問題

Hexune

答えて

0

を解決

{{render_esi(controller("GestionJeuBundle:Default:social")) }} 

のためにそれを変更

{{render(controller("GestionJeuBundle:Default:social")) }} 

でこのアクションをレンダリングして、 Symfonyでデバッグ環境を使用する場合、ワニスいつもは、あなたの要求をバックエンドに渡します。

私は

{{render(controller("GestionJeuBundle:Default:social")) }} 

は私の問題解決

{{render_esi(controller("GestionJeuBundle:Default:social")) }} 

のためにそれを変更すると、このアクションをレンダリングした

+0

やあ、あなたの答えのおかげで、残念ながらそれは生産にまったく同じことを行います環境 – Hexune

+0

バックエンドがプロキシに返すヘッダーは何ですか? – eRIZ

+0

私のヘッダーは良い価値があるようです。私のアクションのレスポンスヘッダーには次のようなものがあります:(cache-control => public、s-maxage = 600、x-debug-token \t => 1df192)リクエストヘッダーにキャッシュに関する情報があるかどうかはわかりません。 – Hexune

関連する問題