Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New hook: cache_clearing_end #1762

Closed
1 task done
gilbert-hop opened this issue Jan 24, 2022 · 5 comments · Fixed by #2108
Closed
1 task done

New hook: cache_clearing_end #1762

gilbert-hop opened this issue Jan 24, 2022 · 5 comments · Fixed by #2108

Comments

@gilbert-hop
Copy link
Contributor

Is your feature request related to a problem? Please describe.
We'd like to create some extensions that can fire after the user click clear cache in the CP.

Describe the solution you'd like
When the user chooses to flush cache in the Cache Manager, an extension hook is triggered.

Describe alternatives you've considered

Teachability, Documentation, Adoption, Migration Strategy
cache_clearing_end ($witch = 'all')
Fires when the cache clearing sequence has ended.

  • I am capable and would like to work on implementation of this feature if it is considered.
@intoeetive
Copy link
Contributor

Wouldn't it be better to implement the hook in functions library, or the cache library itself? Otherwise, I think the more hooks, the better

@gilbert-hop
Copy link
Contributor Author

In my test, I added to the legacy/libraries/Functions.php

    /**
     * Delete cache files
     *
     * @access	public
     * @param	string
     * @return	string
     */
    public function clear_caching($which, $sub_dir = '')
    {
        $options = array('page', 'db', 'tag', 'sql');

        if (in_array($which, $options)) {
            ee()->cache->delete('/' . $which . '_cache/');
        } elseif ($which == 'all') {
            foreach ($options as $option) {
                ee()->cache->delete('/' . $option . '_cache/');
            }
        }
        if ($which == 'jumpmenu') {
            ee('CP/JumpMenu')->clearAllCaches();
        }
        if (ee()->extensions->active_hook('cache_clearing_end') === TRUE) {
            $result = ee()->extensions->call('cache_clearing_end', $which);
        }
    }

I think this is the desired location?

@intoeetive
Copy link
Contributor

It probably is. Just be aware that in some places ee()->cache->delete is called directly as well to clear some very specific caches

@gilbert-hop
Copy link
Contributor Author

But the cache_clearning() method is not called every time ee()->cache->delete() is called right? Basically, I want to fire a hook when the user click Clear Caches on ?/cp/utilities/cache. Or are you saying that we should add the extension to the cache library directly so that all ee()->cache->delete() calls will trigger the extension hook?

@intoeetive
Copy link
Contributor

legacy/libraries/Functions.php might be the good place then

intoeetive pushed a commit that referenced this issue Aug 31, 2022
* Adding extension hook to be executed upon cache clearing

* Adding changelog line

* Checking extension exist before checking active_hook

* Removing patch notes

Co-authored-by: Gilbert <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants