File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change 1
- # Performance
1
+ # Performance and Cache
2
2
3
3
## Enabling the Built-in HTTP Cache Invalidation System
4
4
@@ -68,6 +68,44 @@ final class UserResourcesSubscriber implements EventSubscriberInterface
68
68
}
69
69
```
70
70
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
+
71
109
## Enabling the Metadata Cache
72
110
73
111
Computing metadata used by the bundle is a costly operation. Fortunately, metadata can be computed once and then cached.
You can’t perform that action at this time.
0 commit comments