Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions gentle-introduction/en/12-Caching.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ Removing cached partials and components is a little trickier. As you can pass th
<?php include_partial('user/my_partial', array('user' => $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.

Expand All @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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:

Expand Down
12 changes: 4 additions & 8 deletions gentle-introduction/it/12-Caching.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ Symfony identifica un partial in cache con un prefisso speciale (`sf_cache_parti
<?php include_partial('user/my_partial', array('user' => $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.
Expand All @@ -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`.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 4 additions & 8 deletions gentle-introduction/ja/12-Caching.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ symfony コマンドラインの `cache:clear`タスクはキャッシュ (HTML
<?php include_partial('user/my_partial', array('user' => $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` に基づいたパーシャルからキャッシュをクリーンアップする作業が簡単になります。

Expand All @@ -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は例を示しています。

Expand All @@ -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**
>**クリアするキャッシュの選択に悩む**
Expand Down Expand Up @@ -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()`を呼び出します:

Expand Down