Skip to content

Commit 6ef63c1

Browse files
committed
Update docs
1 parent 5ceac85 commit 6ef63c1

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

plugins/optimization-detective/docs/hooks.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,28 +238,28 @@ add_filter( 'od_metrics_storage_lock_ttl', function ( int $ttl ): int {
238238

239239
### Filter: `od_url_metric_freshness_ttl` (default: 1 week in seconds)
240240

241-
Filters the freshness age (TTL) for a given URL Metric.
241+
Filters age (TTL) for which a URL Metric can be considered fresh.
242242

243-
* A value of zero (0) considers URL Metrics to always be stale.
244-
* A positive value (e.g., HOUR_IN_SECONDS) sets the TTL for URL Metric freshness. In practice, the value should be at least an hour.
245-
* A negative value (-1) disables timestamp-based freshness checks, making URL Metrics stay fresh indefinitely unless the ETag changes.
243+
The freshness TTL (time to live) value can be one of the following values:
246244

247-
For sites where content doesn't change frequently, you can disable the timestamp-based staleness check:
245+
* A positive integer (e.g. `3600`, `HOUR_IN_SECONDS`) allows a URL Metric to be fresh for a given period of time into the future.
246+
* A negative integer (`-1`) disables timestamp-based freshness checks, making URL Metrics stay fresh indefinitely unless the current ETag changes.
247+
* A value of zero (`0`) considers URL Metrics to always be stale, which is useful during development. _Never do this on a production site since this can cause a database write for every visitor!_
248+
249+
The default value is `WEEK_IN_SECONDS` since changes to the post/page (or the site overall) will cause a change to the current ETag used for URL Metrics. This causes the relevant existing URL Metrics with the previous ETag to be considered stale, allowing new URL Metrics to be collected before the freshness TTL has expired. See the `od_current_url_metrics_etag_data` filter to customize the ETag data.
250+
251+
For sites where content doesn't change frequently, you can disable the timestamp-based staleness check as follows:
248252

249253
```php
250254
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
251255
return -1;
252256
} );
253257
```
254258

255-
Note that even if you set a large freshness TTL or use `-1`, a URL Metric can still become stale sooner if the page state changes. This change results in an updated ETag associated with the URL Metric, allowing new URL Metrics to be collected before the freshness TTL has expired. See the `od_current_url_metrics_etag_data` filter to customize the ETag data.
256-
257-
During development, this can be useful to set to zero so that you don't have to wait for new URL Metrics to be requested when engineering a new optimization:
259+
As noted above, during development you can set the freshness TTL to zero so that you don't have to wait for new URL Metrics to be requested when developing a new optimization:
258260

259261
```php
260-
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
261-
return 0;
262-
} );
262+
add_filter( 'od_url_metric_freshness_ttl', '__return_zero' );
263263
```
264264

265265
### Filter: `od_minimum_viewport_aspect_ratio` (default: 0.4)

plugins/optimization-detective/storage/data.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,11 @@
2424
*/
2525
function od_get_url_metric_freshness_ttl(): int {
2626
/**
27-
* Filters the freshness age (TTL) for a given URL Metric.
28-
*
29-
* The freshness TTL can be:
30-
* - Zero: URL Metrics are always considered stale based on timestamp
31-
* - Positive: URL Metrics older than this value (in seconds) are considered stale
32-
* - Negative: Timestamp-based staleness checks are disabled, relying solely on ETag changes
33-
*
34-
* In practice, the value should be at least an hour.
27+
* Filters age (TTL) for which a URL Metric can be considered fresh.
3528
*
3629
* @since 0.1.0
3730
* @since n.e.x.t Negative values disable timestamp-based freshness checks.
31+
* @link https://github.com/WordPress/performance/blob/trunk/plugins/optimization-detective/docs/hooks.md#:~:text=Filter%3A%20od_url_metric_freshness_ttl
3832
*
3933
* @param int $ttl Expiration TTL in seconds. Defaults to 1 week.
4034
*/
@@ -238,6 +232,7 @@ static function ( $post ): ?array {
238232
* Filters the data that goes into computing the current ETag for URL Metrics.
239233
*
240234
* @since 0.9.0
235+
* @link https://github.com/WordPress/performance/blob/trunk/plugins/optimization-detective/docs/hooks.md#:~:text=Filter%3A%20od_current_url_metrics_etag_data
241236
*
242237
* @param array<string, mixed> $data Data.
243238
*/

0 commit comments

Comments
 (0)