api-platform / api-platform/core

Allowing http cache validation

Abierto
#8,043 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
PHP
Estrellas
2.6k
Forks
980
Merge medio
2 d 4 h
PR fusionados (30 d)
49

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.