Skip to content

Commit a9ad22d

Browse files
Cristoforo CervinoCristoforo Cervino
authored andcommitted
update readme
1 parent 9d60a03 commit a9ad22d

File tree

1 file changed

+50
-34
lines changed

1 file changed

+50
-34
lines changed

README.md

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
![Andante Project Logo](https://github.com/andanteproject/timestampable-bundle/blob/main/andanteproject-logo.png?raw=true)
2-
# Timestampable Bundle
3-
#### Symfony Bundle - [AndanteProject](https://github.com/andanteproject)
2+
# Timestampable Bundle
3+
#### Symfony Bundle - [Andante Project](https://github.com/andanteproject)
44
[![Latest Version](https://img.shields.io/github/release/andanteproject/timestampable-bundle.svg)](https://github.com/andanteproject/timestampable-bundle/releases)
55
![Github actions](https://github.com/andanteproject/timestampable-bundle/actions/workflows/ci.yml/badge.svg?branch=main)
66
![Framework](https://img.shields.io/badge/Symfony-5.x|6.x|7.x|8.x-informational?Style=flat&logo=symfony)
7-
![Php8](https://img.shields.io/badge/PHP-%208.x-informational?style=flat&logo=php)
8-
![PhpStan](https://img.shields.io/badge/PHPStan-Level%208-success?style=flat&logo=php)
7+
![Php8](https://img.shields.io/badge/PHP-8.x-informational?style=flat&logo=php)
8+
![PhpStan](https://img.shields.io/badge/PHPStan-Level%208-success?style=flat&logo=php)
99

10-
A Symfony Bundle to handle entity `createdAt` and `updatedAt` dates with Doctrine. 🕰
10+
A Symfony Bundle to handle entity `createdAt` and `updatedAt` dates with Doctrine. 🕰
1111

1212
## Requirements
1313
Symfony 5.x–8.x and PHP 8.2.
@@ -30,42 +30,37 @@ $ composer require andanteproject/timestampable-bundle
3030
After [install](#install), ensure the bundle is registered in your Symfony bundles list (`config/bundles.php`):
3131
```php
3232
return [
33-
// bundles...
33+
// ...
3434
Andante\TimestampableBundle\AndanteTimestampableBundle::class => ['all' => true],
35-
// bundles...
35+
// ...
3636
];
3737
```
3838
This is done automatically if you use [Symfony Flex](https://flex.symfony.com). Otherwise, register it manually.
3939

4040
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.
4242

4343
```php
4444
<?php
4545

4646
namespace App\Entity;
4747

48+
use Doctrine\DBAL\Types\Types;
4849
use Doctrine\ORM\Mapping as ORM;
4950
use Andante\TimestampableBundle\Timestampable\TimestampableInterface;
5051
use Andante\TimestampableBundle\Timestampable\TimestampableTrait;
5152

52-
/**
53-
* @ORM\Entity()
54-
*/
53+
#[ORM\Entity]
5554
class Article implements TimestampableInterface // <-- implement this
5655
{
5756
use TimestampableTrait; // <-- add this
5857

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)]
6461
private ?int $id = null;
6562

66-
/**
67-
* @ORM\Column(type="string")
68-
*/
63+
#[ORM\Column(type: Types::STRING)]
6964
private string $title;
7065

7166
public function __construct(string $title)
@@ -93,34 +88,30 @@ You should see new columns named `created_at` and `updated_at` ([can I change th
9388
| **Both** | `Andante\TimestampableBundle\Timestampable\TimestampableInterface` | `Andante\TimestampableBundle\Timestampable\TimestampableTrait` |
9489

9590
## Usage without the trait
91+
9692
```php
9793
<?php
9894

9995
namespace App\Entity;
10096

97+
use Doctrine\DBAL\Types\Types;
10198
use Doctrine\ORM\Mapping as ORM;
10299
use Andante\TimestampableBundle\Timestampable\TimestampableInterface;
103100

104-
/**
105-
* @ORM\Entity()
106-
*/
101+
#[ORM\Entity]
107102
class Article implements TimestampableInterface // <-- implement this
108103
{
109104
// No trait needed
110105

111-
/**
112-
* @ORM\Id
113-
* @ORM\GeneratedValue
114-
* @ORM\Column(type="integer")
115-
*/
106+
#[ORM\Id]
107+
#[ORM\GeneratedValue]
108+
#[ORM\Column(type: Types::INTEGER)]
116109
private ?int $id = null;
117110

118-
/**
119-
* @ORM\Column(type="string")
120-
*/
111+
#[ORM\Column(type: Types::STRING)]
121112
private string $title;
122113

123-
// DO NOT use ORM annotations to map these properties. See the configuration section for details.
114+
// DO NOT use ORM attributes to map these properties. See the configuration section for details.
124115
private ?\DateTimeImmutable $createdAt = null;
125116
private ?\DateTimeImmutable $updatedAt = null;
126117

@@ -152,14 +143,39 @@ class Article implements TimestampableInterface // <-- implement this
152143
```
153144
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).
154145

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+
155161
## Configuration (completely optional)
156162
This bundle is built to save you time and follow best practices out of the box.
157163

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

160166
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+
161176
```yaml
162177
andante_timestampable:
178+
metadata_cache_warmer_enabled: false # set to true to prewarm metadata at cache build time
163179
default:
164180
created_at_property_name: createdAt # default: createdAt
165181
# Default property for createdAt in entities implementing
@@ -172,8 +188,8 @@ andante_timestampable:
172188
# Database column name for the created date.
173189
# If null, your Doctrine naming strategy is used
174190
updated_at_column_name: updated_at # default: null
175-
# Database column name for the updated date.
176-
# If null, your Doctrine naming strategy is used
191+
# Database column name for the updated date.
192+
# If null, your Doctrine naming strategy is used
177193
entity: # Per-entity overrides
178194
Andante\TimestampableBundle\Tests\Fixtures\Entity\Organization:
179195
created_at_property_name: createdAt

0 commit comments

Comments
 (0)