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
This is done automatically if you use [Symfony Flex](https://flex.symfony.com). Otherwise, register it manually.
39
39
40
40
Suppose you have an `App\Entity\Article` Doctrine entity and want to track created and updated dates.
41
-
All you need to do is implement`Andante\TimestampableBundle\Timestampable\TimestampableInterface` and use the `Andante\TimestampableBundle\Timestampable\TimestampableTrait` trait.
41
+
Implement`Andante\TimestampableBundle\Timestampable\TimestampableInterface` and use the `Andante\TimestampableBundle\Timestampable\TimestampableTrait` trait.
42
42
43
43
```php
44
44
<?php
45
45
46
46
namespace App\Entity;
47
47
48
+
use Doctrine\DBAL\Types\Types;
48
49
use Doctrine\ORM\Mapping as ORM;
49
50
use Andante\TimestampableBundle\Timestampable\TimestampableInterface;
50
51
use Andante\TimestampableBundle\Timestampable\TimestampableTrait;
51
52
52
-
/**
53
-
* @ORM\Entity()
54
-
*/
53
+
#[ORM\Entity]
55
54
class Article implements TimestampableInterface // <--implementthis
56
55
{
57
56
useTimestampableTrait; // <--addthis
58
57
59
-
/**
60
-
*@ORM\Id
61
-
*@ORM\GeneratedValue
62
-
*@ORM\Column(type="integer")
63
-
*/
58
+
#[ORM\Id]
59
+
#[ORM\GeneratedValue]
60
+
#[ORM\Column(type:Types::INTEGER)]
64
61
private?int$id = null;
65
62
66
-
/**
67
-
*@ORM\Column(type="string")
68
-
*/
63
+
#[ORM\Column(type:Types::STRING)]
69
64
privatestring$title;
70
65
71
66
publicfunction__construct(string$title)
@@ -93,34 +88,30 @@ You should see new columns named `created_at` and `updated_at` ([can I change th
@@ -152,14 +143,39 @@ class Article implements TimestampableInterface // <-- implement this
152
143
```
153
144
This lets you use different property names (e.g. `created` and `updated` instead of `createdAt` and `updatedAt`). You must specify these in the [bundle configuration](#configuration-completely-optional).
154
145
146
+
## Metadata cache warming
147
+
148
+
The bundle discovers which entities are timestampable and how their `createdAt` / `updatedAt` properties and columns are configured. That information is **metadata**: it is computed once and then cached in a PHP file under your cache directory so later requests can reuse it without scanning entities again.
149
+
150
+
By default, metadata is built **on first use**: the first time a timestampable entity is persisted or updated in a request, the bundle builds metadata for all mapped entities, caches it in memory and writes it to disk. Subsequent requests (and the same request) then use the cached metadata. For most applications this is enough and you do not need to change anything.
151
+
152
+
If you want to avoid any metadata computation on the **first** request (e.g. in production after a deploy, or in CI when running a single command), you can enable **cache warming**. When enabled, a Symfony cache warmer runs during `cache:warmup` (and when the cache is built on the first request in dev). It precomputes timestampable metadata for all known Doctrine entities and writes it to the cache file. After that, the first real request already uses the prebuilt metadata.
153
+
154
+
**When to enable it**
155
+
156
+
-**Leave it disabled** (default) if you are fine with the first request (or first command) doing a bit of extra work once per cache build.
157
+
-**Enable it** if you care about consistent cold-start performance (e.g. serverless, CI, or strict SLAs on the first request after deploy).
158
+
159
+
You can turn it on in the [configuration](#configuration-completely-optional) with `metadata_cache_warmer_enabled: true`.
160
+
155
161
## Configuration (completely optional)
156
162
This bundle is built to save you time and follow best practices out of the box.
157
163
158
-
You do not need an `andante_timestampable.yml` config file in your application.
164
+
You do not need an `andante_timestampable.yaml` config file in your application.
159
165
160
166
If you need to customize it (e.g. for legacy code), you can change most behavior via the bundle configuration:
167
+
168
+
### Metadata cache warmer
169
+
170
+
See [Metadata cache warming](#metadata-cache-warming) for a full explanation. Summary:
171
+
172
+
| Option | Default | Description |
173
+
|--------|---------|-------------|
174
+
|`metadata_cache_warmer_enabled`|`false`| Set to `true` to precompute timestampable metadata during cache warmup (e.g. `cache:warmup`). Metadata is written to `%kernel.cache_dir%/timestampable_metadata.php`. |
175
+
161
176
```yaml
162
177
andante_timestampable:
178
+
metadata_cache_warmer_enabled: false # set to true to prewarm metadata at cache build time
0 commit comments