- Issue created by @camilo.escobar
While hook_robotstxt()
is an excellent mechanism for altering yourwebsite.com/robots.txt
, the output is typically cached on most Drupal sites. As a result, it may serve outdated data unless the cache is manually cleared or the robotstxt
cache tag is programmatically invalidated. This becomes especially important when lines are added dynamically based on database content or external APIs.
Right now, the only action that invalidates the cache is submitting the configuration form at /admin/config/search/robotstxt
.
In practice, content managers or admins are unlikely to know that this step is required to keep yourwebsite.com/robots.txt
up to date. And realistically, no one wants to repeatedly save a config form or clear the entire Drupal cache just to refresh the content of the file.
hook_cron()
to read that setting and invalidate the robotstxt
cache tag if enabled:Cache::invalidateTags(['robotstxt']);
This would provide a simple, automated way to ensure the robots.txt
content stays current.
New settings page to provide a checkbox to "Invalidate robots.txt cache on each cron run".
No
No
Active
1.6
Code