4

I added a new hook inside a module (hook_cart_commerce_pricecomponent_type_info_alter), which cache have to clear to only update that new hook? I mean i do not want to clear all caches.

Administration menu? Class registry? Menu? Page and else? Theme registry? Token registry? Update data?

1
  • I'm not sure exactly but it'll be either hook_info or module_implements (or maybe both) in the cache_bootstrap bin. You can't invalidate a single hook implementation (unless you alter the cache item manually) so the whole lot will be rebuilt on the next request.
    – Clive
    Jul 31, 2015 at 13:19

5 Answers 5

3

To register a new hook, you can clear the following caches:

cache_clear_all('module_implements', 'cache_bootstrap');
cache_clear_all('hook_info', 'cache_bootstrap');

More info: https://api.drupal.org/api/drupal/includes%21module.inc/function/module_implements/7

1

If using drush, drush cc registry will suffice for that hook.

0

Theme Registry

The most common case for manually registering hooks is in forms. Form elements are them-able but there is another dimension to how they are processed. There are the generic elements such as check-boxes, radio selects, submit button, drop down menus, etc. Each element is them-able on its own and overriding it does not require manually registering the hooks associated with it. The extra dimension comes in with custom forms where each element is arranged in very specific ways. In some forms, they are already arranged, themed and registered. For these forms, manually registering is not required. The forms that are not explicitly themed will default to how form API renders them.

1
  • The OP is not asking about manually registering a hook. They changed the code of a module without first disabling it.
    – apaderno
    Sep 12, 2015 at 15:48
0

You can use:

-1

You can rebuild the registry to force Drupal to re-scan the code files and register your hook implementations. To do this with drush:

  1. Before first use, install registry_rebuild:

    drush dl registry_rebuild
    
  2. Rebuild the registry:

    drush rr
    

This worked for me in a case where both drush cc registry, drush cc all and clearing the hook_info and module_implements caches failed.

2
  • 1
    The question was how to avoid clearing all caches when a new hook is added. drush rr will definitely clear all caches. Mar 2, 2019 at 19:59
  • @AlexBukach As I mentioned in the answer, drush rr is an option for cases where even clearing all caches does not help, so certainly clearing any one cache would not help either in such a case. I don't remember anymore what kind of special case I had that needed drush rr, but one day somebody will have one again, and love to find this answer …
    – tanius
    Mar 7, 2019 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.