api-platform / api-platform/core

Allowing http cache validation

Aperta
#8,043 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
PHP
Stelle
2.6k
Fork
980
Merge medio
2g 4h
PR unite (30g)
49

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.