From c9fed73a7906f8e424a6685f095a9d2c79d7d826 Mon Sep 17 00:00:00 2001 From: Peter Bowyer Date: Tue, 12 Mar 2013 12:32:51 +0000 Subject: [PATCH 1/3] Update 12-Caching.markdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed ➥ in code blocks, as breaking current live documentation. --- gentle-introduction/it/12-Caching.markdown | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gentle-introduction/it/12-Caching.markdown b/gentle-introduction/it/12-Caching.markdown index 47a70a4..e3b4813 100644 --- a/gentle-introduction/it/12-Caching.markdown +++ b/gentle-introduction/it/12-Caching.markdown @@ -416,8 +416,7 @@ Symfony identifica un partial in cache con un prefisso speciale (`sf_cache_parti $user) ?> // È identificato nella cache come - @sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key=bf41dd9c84d59f3574a5da244626dcc8 + @sf_cache_partial?module=user&action=_my_partial&sf_cache_key=bf41dd9c84d59f3574a5da244626dcc8 Teoricamente è possibile rimuovere un partial in cache tramite il metodo `remove()` conoscendo il valore dei parametri hash usati per identificarlo, ma ciò è veramente poco praticabile. Fortunatamente, aggiungendo un parametro `sf_cache_key` alla chiamata dell'helper `include_partial()`, è possibile identificare il partial in cache con tale chiave. @@ -435,8 +434,7 @@ Listato 12-10 - Rimozione di un partial dalla cache @sf_cache_partial?module=user&action=_my_partial&sf_cache_key=12 // Elimina _my_partial per uno specifico utente in cache con - $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key='.$user->getId()); + $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial&sf_cache_key='.$user->getId()); Per eliminare dalla cache frammento di template, viene utilizzato lo stesso metodo `remove()`. La chiave che identifica il frammento nella cache è lo stesso prefisso `sf_cache_partial`, il nome del modulo, quello dell'azione e il parametro `sf_cache_key`. @@ -455,8 +453,7 @@ Listato 12-11 - Eliminare frammento dalla cache @sf_cache_partial?module=user&action=list&sf_cache_key=users // Eliminato con - $cacheManager->remove('@sf_cache_partial?module=user&action=list - ➥ &sf_cache_key=users'); + $cacheManager->remove('@sf_cache_partial?module=user&action=list&sf_cache_key=users'); >**SIDEBAR** >L'eliminazione selettiva della cache potrebbe risultare un'operazione delirante per lo sviluppatore @@ -504,8 +501,7 @@ Per rimuovere un profilo utente in cache con id 12 in tutte le lingue, è suffic Questo funziona anche per i partial: [php] - $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key=*'); // Rimozione per tutte le chiavi + $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial&sf_cache_key=*'); // Rimozione per tutte le chiavi Il metodo `remove()` accetta due parametri in più, consentendo di definire quali host e header `Vary` si vogliono rimuovere dalla cache. Questo perché symfony mantiene una versione di cache per ogni host e header `Vary`, quindi due applicazioni che condividano lo stesso codice ma non lo stesso host utilizzerebbero cache diverse. From 7c11e66c020436814e19780c049b142ab6599b88 Mon Sep 17 00:00:00 2001 From: Peter Bowyer Date: Tue, 12 Mar 2013 12:34:26 +0000 Subject: [PATCH 2/3] =?UTF-8?q?Removing=C2=A0=E2=9E=A5=20from=20sf=5Fcache?= =?UTF-8?q?=5Fkey=20code=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gentle-introduction/en/12-Caching.markdown | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gentle-introduction/en/12-Caching.markdown b/gentle-introduction/en/12-Caching.markdown index e6c9557..6f93bd4 100644 --- a/gentle-introduction/en/12-Caching.markdown +++ b/gentle-introduction/en/12-Caching.markdown @@ -347,8 +347,7 @@ Removing cached partials and components is a little trickier. As you can pass th $user) ?> // Is identified in the cache as - @sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key=bf41dd9c84d59f3574a5da244626dcc8 + @sf_cache_partial?module=user&action=_my_partial&sf_cache_key=bf41dd9c84d59f3574a5da244626dcc8 In theory, you could remove a cached partial with the `remove()` method if you knew the value of the parameters hash used to identify it, but this is very impracticable. Fortunately, if you add a `sf_cache_key` parameter to the `include_partial()` helper call, you can identify the partial in the cache with something that you know. As you can see in Listing 12-10, clearing a single cached partial --for instance, to clean up the cache from the partial based on a modified `User`-- becomes easy. @@ -364,8 +363,7 @@ Listing 12-10 - Clearing Partials from the Cache @sf_cache_partial?module=user&action=_my_partial&sf_cache_key=12 // Clear _my_partial for a specific user in the cache with - $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key='.$user->getId()); + $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial&sf_cache_key='.$user->getId()); To clear template fragments, use the same `remove()` method. The key identifying the fragment in the cache is composed of the same `sf_cache_partial` prefix, the module name, the action name, and the `sf_cache_key` (the unique name of the cache fragment included by the `cache()` helper). Listing 12-11 shows an example. @@ -382,8 +380,7 @@ Listing 12-11 - Clearing Template Fragments from the Cache @sf_cache_partial?module=user&action=list&sf_cache_key=users // Clear it with - $cacheManager->remove('@sf_cache_partial?module=user&action=list - ➥ &sf_cache_key=users'); + $cacheManager->remove('@sf_cache_partial?module=user&action=list&sf_cache_key=users'); >**SIDEBAR** >Selective Cache Clearing Can damage your Brain @@ -427,8 +424,7 @@ To remove the cached profile of the user having an `id` of `12` in all languages This also works for partials: [php] - $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key=*'); // Remove for all keys + $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial&sf_cache_key=*'); // Remove for all keys The `remove()` method accepts two additional parameters, allowing you to define which hosts and vary headers you want to clear the cache for. This is because symfony keeps one cache version for each host and vary headers, so that two applications sharing the same code base but not the same hostname use different caches. This can be of great use, for instance, when an application interprets the subdomain as a request parameter (like `http://php.askeet.com` and `http://life.askeet.com`). If you don't set the last two parameters, symfony will remove the cache for the current host and for the `all` vary header. Alternatively, if you want to remove the cache for another host, call `remove()` as follows: From 6bb4f9552152eef01cbd433bee9515dd5ea2d1d3 Mon Sep 17 00:00:00 2001 From: Peter Bowyer Date: Tue, 12 Mar 2013 12:35:20 +0000 Subject: [PATCH 3/3] =?UTF-8?q?Removing=C2=A0=E2=9E=A5=20from=20sf=5Fcache?= =?UTF-8?q?=5Fkey=20code=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gentle-introduction/ja/12-Caching.markdown | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gentle-introduction/ja/12-Caching.markdown b/gentle-introduction/ja/12-Caching.markdown index 4d3dca5..fff1ae0 100644 --- a/gentle-introduction/ja/12-Caching.markdown +++ b/gentle-introduction/ja/12-Caching.markdown @@ -347,8 +347,7 @@ symfony コマンドラインの `cache:clear`タスクはキャッシュ (HTML $user) ?> // つぎのようなキャッシュに分類される - @sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key=bf41dd9c84d59f3574a5da244626dcc8 + @sf_cache_partial?module=user&action=_my_partial&sf_cache_key=bf41dd9c84d59f3574a5da244626dcc8 理論上では、区別するために使われるパラメーターのハッシュの値を知っているのであれば、キャッシュされたパーシャルを `remove()` メソッドで削除できます。しかし、これは現実的な方法ではありません。幸いにして、`sf_cache_key` パラメーターを `include_partial()` ヘルパー呼び出しに追加する場合、あなたにとって既知のものとしてキャッシュのなかのパーシャルを識別できます。リスト12-10で見ることができるように、単独のキャッシュされたパーシャルをクリアする作業、たとえば、修正された `User` に基づいたパーシャルからキャッシュをクリーンアップする作業が簡単になります。 @@ -364,8 +363,7 @@ symfony コマンドラインの `cache:clear`タスクはキャッシュ (HTML @sf_cache_partial?module=user&action=_my_partial&sf_cache_key=12 // つぎのコードでキャッシュの特定のユーザーに対する _my_partial をクリアする - $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key='.$user->getId()); + $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial&sf_cache_key='.$user->getId()); テンプレートフラグメントをクリアするには、同じ `remove()` メソッドを使います。キャッシュのフラグメントを指定するキーは同じ `sf_cache_partial` のプレフィックス、モジュールの名前、アクションの名前と `sf_cache_key/` で構成されます (キャッシュフラグメントのユニークな名前は `cache()` ヘルパーに含まれます)。リスト12-11は例を示しています。 @@ -382,8 +380,7 @@ symfony コマンドラインの `cache:clear`タスクはキャッシュ (HTML @sf_cache_partial?module=user&action=list&sf_cache_key=users // つぎのコードでクリアする - $cacheManager->remove('@sf_cache_partial?module=user&action=list - ➥ &sf_cache_key=users'); + $cacheManager->remove('@sf_cache_partial?module=user&action=list&sf_cache_key=users'); >**SIDEBAR** >**クリアするキャッシュの選択に悩む** @@ -427,8 +424,7 @@ symfony コマンドラインの `cache:clear`タスクはキャッシュ (HTML これはパーシャルに対しても機能します: [php] - $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial - ➥ &sf_cache_key=*'); // すべてのキーに対して除去する + $cacheManager->remove('@sf_cache_partial?module=user&action=_my_partial&sf_cache_key=*'); // すべてのキーに対して除去する `remove()` メソッドは2つの追加パラメーターを受けとり、キャッシュをクリアしたいホストと vary ヘッダーを定義できるようにします。symfony はそれぞれのホストと vary ヘッダーに対して1つのキャッシュバージョンを保存するので、同じコードベースを共有するが同じホスト名を共有しない2つのアプリケーションは異なるキャッシュを使います。これはアプリケーションがサブドメイン (たとえば `http://php.askeet.com`と`http://life.askeet.com`) をリクエストパラメーターとして解釈するとき、とても便利です。最後の2つのパラメーターを設定しない場合、symfony は現在のホストと `all` の vary ヘッダーに対してキャッシュを除去します。代わりに、別のホストに対してキャッシュを除去したい場合、つぎのように`remove()`を呼び出します: