Skip to content

Commit a2b4a2f

Browse files
committed
Update hooks.md
Signed-off-by: Shyamsundar Gadde <[email protected]>
1 parent eeae684 commit a2b4a2f

File tree

1 file changed

+9
-3
lines changed
  • plugins/optimization-detective/docs

1 file changed

+9
-3
lines changed

plugins/optimization-detective/docs/hooks.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,21 @@ 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. The freshness TTL must be at least zero, in which it considers URL Metrics to always be stale. In practice, the value should be at least an hour. If your site content does not change frequently, you may want to increase the TTL even longer, say to a month:
241+
Filters the freshness age (TTL) for a given URL Metric.
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.
246+
247+
For sites where content doesn't change frequently, you can disable the timestamp-based staleness check:
242248

243249
```php
244250
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
245-
return MONTH_IN_SECONDS;
251+
return -1;
246252
} );
247253
```
248254

249-
Note that even if you have large freshness TTL a URL Metric can still become stale sooner; if the page state changes then this results in a change to the ETag associated with a URL Metric. This will allow new URL Metrics to be collected before the freshness TTL has transpired. See the `od_current_url_metrics_etag_data` filter to customize the ETag data.
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.
250256

251257
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:
252258

0 commit comments

Comments
 (0)