In your particular case, one solution you might consider is
Javascript. Have the partial output some inline javascript which
generates a random number and inputs it into the desired place (hidden
form field, etc). I have used this approach successfully to get a
random image to show up on an otherwise cached page.
Another more general solution to this problem might be to split your
view into 2 partials-- one for the stuff that will be cached
(_show.php), and the other existing one for the comment box
(_addcomment.php). Simply have the template pass along the needed info
to the _show.php partial, and turn on caching for that partial. This
means that the view will still need to be rendered (minimal overhead),
but the partial will be cached, so no need for the DB queries. The
downside to this approach is just in the messiness of adding an extra
layer of view code. But it should still be much faster than running
with the cache turned off entirely.
-vanchuck
On Jun 16, 5:55 am, ksn135 <[EMAIL PROTECTED]> wrote:
> I've action `show` that display article text with images from
> database.
> Every article at the bottom have `add comment` form with antispam
> feature.
> I would like to cache entire action to reduce page load time (many db
> queries).
> BUT I need to execute two lines of antispam code on each request:
>
> $antispam = new AntiSpam(); $antispam_string = $antispam->rand(5);
> $this->getUser()->setAttribute('antispam', $antispam_string);
>
> I've tried to use several methods:
> 1) just cache action. code in template or partial
> show:
> enabled: on
> _addcomment:
> enabled: off
>
> Action not executed. good. Template cached.
> Antispam code inside cached partial/template NOT executed
>
> 2) cache only partials inside template, code in template/partial:
> show:
> enabled: off
> _addcomment:
> enabled: off
> _rubrica:
> enabled: on
> _author:
> enabled: on
> _author:
> enabled: on
>
> Action executed. Many db queries.
> Antispam code executed.
>
> But it seems that second method has almost similar timings when the
> cache is completly off.
>
> SO, the question is :
>
> "Is there some other method to execute two lines of code in
> cached action ?"
>
> Any ideas? May be I'm reinventing the wheel ?
>
> Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---