Cache Action Recording

I’ve just started working in Yii and I’m trying to add some functionality to the CClientScript, before beginning overriding functions I’m trying to understand everything it’s doing so I don’t trip myself up later by not including something or including it wrong.

I’ve spotted a method call when registering scripts/files:


I’ve followed this chain down through a few classes to COutputCache in one case and seen the replayActions function. What is this used for? Is there any thing that requires this or is it as my suspicions and it’s just a useful debugging feature to track caching?


Why are caching actions recorded for later replaying?

When you do fragment caching, and inside your cached fragment there’s any CSS/Javascript registered, this registration has to be replayed when the cached fragment is served. This is because the script can be rendered at a location that is not cached (e.g. POS_HEAD). This can happen pretty easily for example when you use complex widgets in fragments register some assets.

OK that makes some sense, so what happens to all the scripts that are registered in the same rendering chain but not specific to that view fragment e.g.:




  ->page Fragment cached


Wouldn’t jquery and UI then be included as they were registered at the same time the view was called, and all that was recorded was the client script registering which script should be cached?

I’m confused as to why there’s not more documentation about some features. Yii’s documentation is one of the best I’ve seen but the framework is so good that it still only covers 40% of it :s

The comment in recordCachingAction in CClientScript says: " Records a method call when an output cache is in effect." When you follow execution workflow, you’ll find that in CController the action is only recorded if there’s something on the caching stack. In COutputCache you’ll find that the widget pushes itself on that stack in init() and removes itself afterwards in run(). So no other script registrations outside will get cached (except there’s a nested fragment).

I think the reason why this is not documented is because it are really internals of how Yii tries to be as smart as possible and just make things work. So you often have to read the code when you want to find out how it works under the hood. But i agree that even that is sometimes a bit hard. But if you add it to the docs, most users will just get confused, as they don’t need this extra information.

Ah think I’ve got it now, its a little hook to let Yii do it’s clever caching. I can deal with that :P not something that needs to be extended just included wherever caching might need to be used.