You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/performance.md
+87-9Lines changed: 87 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,9 @@ Update your Caddyfile with the following configuration:
71
71
72
72
This will tell to caddy to use the HTTP cache and activate the tag-based invalidation API. You can refer to the [cache-handler documentation](https://github.com/caddyserver/cache-handler) or the [souin website documentation](https://docs.souin.io) to learn how to configure the HTTP cache server.
73
73
74
-
Setup the HTTP cache invalidation in your API Platform project
74
+
Set up HTTP cache invalidation in your API Platform project using the Symfony or Laravel configuration below:
75
+
76
+
##### Cache Invalidation Configuration using Symfony
75
77
76
78
```yaml
77
79
api_platform:
@@ -83,6 +85,24 @@ api_platform:
83
85
purger: api_platform.http_cache.purger.souin
84
86
```
85
87
88
+
##### Cache Invalidation Configuration using Laravel
89
+
90
+
```php
91
+
<?php
92
+
// config/api-platform.php
93
+
return [
94
+
// ....
95
+
'http_cache'=> [
96
+
'invalidation'=> [
97
+
// We assume that your API can reach your caddy instance by the hostname http://caddy.
98
+
// The endpoint /souin-api/souin is the default path to the invalidation API.
Support for reverse proxies other than Varnish or Caddy with the HTTP cache module can be added by implementing the `ApiPlatform\HttpCache\PurgerInterface`.
128
175
Three purgers are available, the built-in caddy HTTP cache purger (`api_platform.http_cache.purger.souin`), the HTTP tags (`api_platform.http_cache.purger.varnish.ban`), the surrogate key implementation
129
176
(`api_platform.http_cache.purger.varnish.xkey`). You can specify the implementation using the `purger` configuration node,
130
-
for example, to use the `xkey` implementation:
177
+
for example, to use the `Xkey` implementation see the Symfony or Laravel configuration below:
178
+
179
+
### Exemple of Varnish Xkey implementation using Symfony
131
180
132
181
```yaml
133
182
api_platform:
@@ -147,6 +196,37 @@ api_platform:
147
196
glue: ', '
148
197
```
149
198
199
+
### Exemple of Varnish Xkey implementation using Laravel
In addition to the cache invalidation mechanism, you may want to [use HTTP/2 Server Push to pre-emptively send relations
151
231
to the client](push-relations.md).
152
232
@@ -257,20 +337,18 @@ This feature is enabled by default in the production environment of the API Plat
257
337
### Search Filter
258
338
259
339
When using the `SearchFilter` and case insensitivity, Doctrine will use the `LOWER` SQL function. Depending on your
260
-
driver, you may want to carefully index it by using a [function-based
261
-
index](https://use-the-index-luke.com/sql/where-clause/functions/case-insensitive-search) or it will impact performance
262
-
with a huge collection. [Here are some examples to index LIKE
263
-
filters](https://use-the-index-luke.com/sql/where-clause/searching-for-ranges/like-performance-tuning) depending on your
264
-
database driver.
340
+
driver, you may want to carefully index it by using a [function-based index,](https://use-the-index-luke.com/sql/where-clause/functions/case-insensitive-search) or it will impact performance
341
+
with a huge collection. [Here are some examples to index LIKE filters](https://use-the-index-luke.com/sql/where-clause/searching-for-ranges/like-performance-tuning) depending on your database driver.
265
342
266
343
### Eager Loading
267
344
268
-
By default, Doctrine comes with [lazy loading](https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/working-with-objects.html#by-lazy-loading) - usually a killer time-saving feature but also a performance killer with large applications.
345
+
By default, Doctrine comes with [lazy loading](https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/working-with-objects.html#by-lazy-loading)
346
+
- usually a killer time-saving feature but also a performance killer with large applications.
269
347
270
348
Fortunately, Doctrine offers another approach to solve this problem: [eager loading](https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/working-with-objects.html#by-eager-loading).
271
349
This can easily be enabled for a relation: `#[ORM\ManyToOne(fetch: "EAGER")]`.
272
350
273
-
By default in API Platform, we chose to force eager loading for all relations, with or without the Doctrine
351
+
By default, in API Platform, we chose to force eager loading for all relations, with or without the Doctrine
274
352
`fetch` attribute. Thanks to the eager loading [extension](extensions.md). The `EagerLoadingExtension` will join every
275
353
readable association according to the serialization context. If you want to fetch an association that is not serializable,
276
354
you have to bypass `readable` and `readableLink` by using the `fetchEager` attribute on the property declaration, for example:
0 commit comments