api-platform / api-platform/core

Allowing http cache validation

Đang mở
#8,043 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
PHP
Star
2.6k
Fork
980
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
49

Mô tả

**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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.