2

symfonyには本当にシンプルなKey-Value-Cacheが必要です。DoctrineやHTTPキャッシングなしのそのようなもの。

<?php
$cacheKey = 'blabla';
if(!$cache->has($cacheKey)) {
    // do some heavy work...
    $cache->set($cacheKey, $heavyWorkResult);
}
$result = $cache->get($cacheKey);

マニュアルで見逃しましたか、それとも別のバンドルが必要ですか?

4

4 に答える 4

2

なんでググらないの?または、knpbundles.comを見て、「キャッシュ」を検索してください。

http://knpbundles.com/search?q=キャッシュ

多分これはあなたのニーズに合ったものです:

https://github.com/winzou/CacheBundle

使用法:

$cache = $this->get('winzou_cache.apc');
// or
$cache = $this->get('winzou_cache.file');
// or
$cache = $this->get('winzou_cache.memcache');
// or
$cache = $this->get('winzou_cache.array');
// or
$cache = $this->get('winzou_cache.xcache');
// or
$cache = $this->get('winzou_cache.zenddata');
// or
$cache = $this->get('winzou_cache'); // in that case, it will use the default driver     defined in config.yml, see below

$cache->save('bar', array('foo', 'bar'));

if ($cache->contains('bar')) {
    $bar = $cache->fetch('bar');
}

$cache->delete('bar');

編集:

これにセッションを使用するのは得策ではありません。セッションはユーザーごとであり、キャッシュされた値は共有できません。また、セッションを使用するときは、シリアライゼーションや、複雑なオブジェクトをセッションに保存するときに発生する可能性のあるその他の問題について考える必要があります。

于 2012-10-12T10:33:18.610 に答える
1

https://github.com/doctrine/cache (doctrine が現在スタンドアロンで使用しているキャッシュシステム)を使用できると思います

于 2013-07-25T02:15:13.077 に答える
0

Symfony のドキュメントから:

use Symfony\Component\HttpFoundation\Session\Session;

$session = new Session();
$session->start();

// set and get session attributes
$session->set('name', 'Drak');
$session->get('name');

http://symfony.com/doc/master/components/http_foundation/sessions.html

于 2012-10-14T02:07:09.243 に答える