Skip to content

Commit 4a2c3d4

Browse files
committed
1 parent a0dd799 commit 4a2c3d4

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

core/performance.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Performance
1+
# Performance and Cache
22

33
## Enabling the Built-in HTTP Cache Invalidation System
44

@@ -68,6 +68,44 @@ final class UserResourcesSubscriber implements EventSubscriberInterface
6868
}
6969
```
7070

71+
## Setting Custom HTTP Cache Headers
72+
73+
The `cache_headers` attribute can be used to set custom HTTP cache headers:
74+
75+
```php
76+
use ApiPlatform\Core\Annotation\ApiResource;
77+
78+
/**
79+
* @ApiResource(cacheHeaders={"max_age"=60, "shared_max_age"=120})
80+
*/
81+
class Book
82+
{
83+
// ...
84+
}
85+
```
86+
87+
For all endpoints related to this resource class, the following HTTP header will be set:
88+
89+
`Cache-Controle: max-age=60, public, s-maxage=120`
90+
91+
It's also possible to set different cache headers per operation:
92+
93+
```php
94+
use ApiPlatform\Core\Annotation\ApiResource;
95+
96+
/**
97+
* @ApiResource(
98+
* itemOperations={
99+
* "get"={"cache_headers"={"max_age"=60, "shared_max_age"=120}}
100+
* }
101+
* )
102+
*/
103+
class Book
104+
{
105+
// ...
106+
}
107+
```
108+
71109
## Enabling the Metadata Cache
72110

73111
Computing metadata used by the bundle is a costly operation. Fortunately, metadata can be computed once and then cached.

0 commit comments

Comments
 (0)