api-platform / api-platform/core

Allowing http cache validation

オープン
#8,043 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
PHP
スター
2.6k
フォーク
980
平均マージ
2日 4時間
マージ済み PR(30日)
49

説明

**Description**
We can easily set http cache expiration headers on resources endpoints, but why not cache validation ?

**Example**
``` diff
#[ApiResource(
itemOperations: [
'get' => [
'security_post_denormalize' => "is_granted('article.read', object)",
'cache_headers' => [
'max_age' => 60,
'shared_max_age' => 120,
+ 'last_modified' => 'object.getPublishedAt()',
+ 'etag' => 'object.computeEtag()',
],
],
],
)
```

which is equivalent to:

``` php
#[Cache(
maxage: 60,
smaxage: 120,
lastModified: 'data.getPublishedAt()',
etag: 'data.computeEtag()',
)]
public function __invoke(Article $data): Response
{
return $data;
}
```

Currently, we have to define a controller for each resource I want to cache, with an empty method (`return $data`) and a `@Cache` annotation. Unless I am missing something, or a better way to do that.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。