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: plugins/optimization-detective/docs/hooks.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -238,28 +238,28 @@ add_filter( 'od_metrics_storage_lock_ttl', function ( int $ttl ): int {
238
238
239
239
### Filter: `od_url_metric_freshness_ttl` (default: 1 week in seconds)
240
240
241
-
Filters the freshness age (TTL) for a given URL Metric.
241
+
Filters age (TTL) for which a URL Metric can be considered fresh.
242
242
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:
246
244
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:
248
252
249
253
```php
250
254
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
251
255
return -1;
252
256
} );
253
257
```
254
258
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:
258
260
259
261
```php
260
-
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
0 commit comments