When trying this module I've been missing drush cache-rebuild. A patch will follow adding some backport-cache-rebuild command.

Comments

Jose Reyero created an issue. See original summary.

jose reyero’s picture

Similar to drush cr for D8, this rebuilds the container and clears all caches.

drush backport-cache-rebuild
  or
drush bcr
markhalliwell’s picture

Title: Add some drush command for cache-rebuild » Rebuild container on hook_flush_caches()
Category: Feature request » Task
Status: Active » Needs work

I would actually prefer that we hook into D7's existing caching API rather than introducing a separate Drush command.

markhalliwell’s picture

Title: Rebuild container on hook_flush_caches() » Invalidate container when registry is rebuilt

Actually, hook_flush_caches() is a no-go since it's invoked during cron runs.

  • markcarver committed ac8f848 on 7.x-4.x
    Issue #2951755 by markcarver, Jose Reyero: Invalidate container when...
markhalliwell’s picture

Status: Needs work » Fixed
jose reyero’s picture

StatusFileSize
new1.68 KB

In the meanwhile I was working on that flush_caches... :-)

I prefer a specific drush command too, but since I had the patch already done, here you are just in case you change your mind or it is some use in the future.

markhalliwell’s picture

In the meanwhile I was working on that flush_caches... :-)

Ah, sorry. Figured I could sneak this in given your timezone :D Should have assigned to myself.

here you are just in case you change your mind or it is some use in the future.

No, hook_flush_caches() can never be used for this because it is invoked when cron runs (which can be 5 minutes or every minute on some sites). This would defeat the whole point of caching a container in the first place.

The appropriate hook that should be used to invalidate the container on a cache clear is hook_registry_files_alter().

markhalliwell’s picture

jose reyero’s picture

Seen what you've finally comitted, looks ok but... I think we still need some drush command on top of that, here's why:

In the case the cointainer is actually broken, like when you get a missing service exception, backport_drupal_kernel() won't return any kernel at all which means we are not rebuilding anything. And this is exactly what happened to me between module versions, I'm already building some stuff on top of this....

So I think we still need some way to recover from a broken container / kernel, which was the purpose of that drush command. Anyway, never mind, I'll come back with a new patch because I think we'll be better off with an actual drush cr -for which I'll try some hook_drush_command_alter, to make it work for D7.

I guess I am not the only one continuously switching from d7 to d8 for several projects and writing 'drush cr' all the time in D7 too just to get some error...

(I'll create a new task for it if you don't mind).

markhalliwell’s picture

Title: Invalidate container when registry is rebuilt » Rebuild container when registry is rebuilt
Status: Fixed » Needs work

I think we'll be better off with an actual drush cr -for which I'll try some hook_drush_command_alter, to make it work for D7.

Backporting the drush cr command would be far more preferable than implementing a custom command, yes.

That being said, I would still argue that drush cr should simply invoke what drush cc all does. Or rather, just proxy to the cache-clear command.

Since this is only invoked when registry_rebuild() is invoked, perhaps we should add an "else" block that does a complete rebuild when the kernel cannot be loaded.

markhalliwell’s picture

Title: Rebuild container when registry is rebuilt » Invalidate or rebuild container when registry is rebuilt

Actually, this is the proper title

markhalliwell’s picture

I'll let you work on this if you want, I'm working on some other things ATM.

  • markcarver committed de6888d on 7.x-4.x
    Issue #2951755 by markcarver, Jose Reyero: Invalidate or rebuild...

  • markcarver committed 08779a0 on 7.x-4.x
    Issue #2951755 by markcarver, Jose Reyero: Invalidate or rebuild...
markhalliwell’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.