Bust cache on user update

I just noticed that updates to a user do not bust the cache - with the new user fields this is something that I expected, as I now store some data there. I guess that problem is not new, I just encountered it for the first time with the custom fields in 2.2.

Luckily it’s an easy fix with the panel hooks:

<?php

$empty_cache = function($user) {
	kirby()->cache()->flush();
};

kirby()->hook('panel.user.update', $empty_cache);
kirby()->hook('panel.user.delete', $empty_cache);
kirby()->hook('panel.avatar.upload', $empty_cache);
kirby()->hook('panel.avatar.delete', $empty_cache);

A question for people that use hooks more frequently than I do: Doesn’t it happen quite often that you execute the same code for at least two events (e.g. update and delete, or create and update)? Maybe the first parameter to the hook function could be an array of events:

kirby()->hook(
  array(
    'panel.user.update',
    'panel.user.delete',
  ), 
  function() {...}
);

I just pushed a new version to the develop branch, which automatically flushes the cache on those events.

I also started a feature branch for a more extended hook API, which makes it possible to register multiple hooks at once as well as registering a single callback for multiple hooks. It will be in 2.3