Posted by fago on January 13, 2012 at 4:21pm
Follow-up to properly fix #996236: drupal_flush_all_caches() does not clear entity info cache (stop-gap fix for D7)
- Data rebuild operations happening during
drupal_flush_all_caches()act on stale/outdated data of other modules and subsystems.
hook_flush_caches()implementations rebuild data on stale caches. Then they return caches to flush, which may contain the data that was just rebuilt.
hook_rebuild()as unique rebuild operation.
- Properly separate cache flushing and static variable resets from rebuild operations.
drupal_flush_all_caches()clears caches, but also issues several kind of rebuilds.
- The menu is rebuilt and module provided configuration-alike data structures (such as node types) are rebuilt.
- There are many interdependencies between the caches and rebuilds.
- Rebuilds may be based on other stale/old/invalid cached data, which hasn't been cleared yet.
- In turn, rebuilt data can be entirely bogus or incomplete.
- Clean environment: Flush all database caches first. (
- Clean environment: Reset all static caches.
- Trigger module rebuilds. Guaranteed to be based on clean+fresh data. (
- Rebuild the menu router. Guaranteed to contain most current data.
- Clear page, JS, and CSS caches. As an attempt to still serve cached pages during the entire operation.
hook_flush_caches()is renamed to
hook_cache_flush()to ensure that modules are only clearing caches.
hook_rebuild()is added as dedicated hook for rebuilding operations.
menu_rebuild()(in menu.inc) is renamed to
menu_router_rebuild(), since the name clashes with
hook_rebuild()when Menu module is installed.
- Some other D8 issue wants to introduce
hook_cache_bins(). That could be renamed into
hook_cache_info()and it would cover the 90% use-case of
hook_cache_flush()here (returning names of cache bins that need to be flushed).
- There's a long-time desire to split menu.inc into router.inc for the router system parts. So
menu_router_rebuild()might be renamed into
router_rebuild()later. The new Symfony kernel might make that obsolete though, we'll see.
- The new configuration system might make some implementations of
hook_rebuild()obsolete (those that attempt to synchronize active configuration with code definitions, such as
node_types_rebuild()). To be investigated later, doesn't matter for this issue.
- This patch unintentionally speeds up cron runs. Cron invokes
hook_flush_caches()but only wants to flush caches. Many of the current implementations are performing additional rebuild operations (e.g., Block module).