api-platform / api-platform/core

Allowing http cache validation

Aberta
#8,043 2 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
PHP
Estrelas
2.6k
Forks
980
Merge médio
2d 4h
PRs com merge (30d)
49

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.