luya-module-cms icon indicating copy to clipboard operation
luya-module-cms copied to clipboard

Hook::on in Block with enabled cache

Open TheMaaarc opened this issue 6 years ago • 6 comments

If you use the Hook::on function in a block with cache enabled it only works once (after cache clear).

Currently I invoke the function in the view file, is there a possibility to exclude certain functions in the block from caching?

TheMaaarc avatar Oct 11 '18 08:10 TheMaaarc

Maybe we can have an event listener which is triggered accordingly (whether its register from cache or not):

$this->on(self::EVENT_AFTER_REGISTER, function() { // do your stuff });

nadar avatar Oct 11 '18 09:10 nadar

@boehsermoe onRegister() and onRegisterFromCache() should trigger an event which blocks can register listeneres while initialize (init() method) (example above)

nadar avatar Feb 27 '19 08:02 nadar

Ok I will take a closer look at the next days.

boehsermoe avatar Mar 01 '19 06:03 boehsermoe

i think $this->trigger(self::EVENT_ON_REGISTER) should do the job, maybe i will find time next week.

nadar avatar Mar 01 '19 09:03 nadar

I think it is a little more difficult. For one the block classes does not have any event handling implemented yet. The other thing is if you override a view from a core block (or other module) you cannot listen on this event without make your own block. It should be able to listen on events via block variants too. What do you think?

boehsermoe avatar Mar 04 '19 21:03 boehsermoe

The event handling can be achieved by using Component instead of BaseObject for InternalBaseBlock. I think this is just a more wide used behavior when registering hooks (or other things) inside a block, therefore this event is used.

nadar avatar Mar 05 '19 07:03 nadar