开发者

Disable smarty caching when logged in

The problem I am trying to solve is nearly identical to this: smarty cache and login states, but I want to know if I can solve this in a specific way.

What I want to do is simply disable all smarty caching if a user is logged in. For example:

$smarty->cache_lifetime = 300;
$smarty->caching = ( $user->is_logged_in ) ? false : 2;
$my_cache_id = $_GET['article_id'];
if( $user->is_logged_in || !$smarty->is_cached('index.tpl',$my_cache_id) ) {
    //Get page d开发者_如何学Pythonata
}
$smarty->display('index.tpl', $my_cache_id);

Granted this would have as much effect as defining dynamic blocks, but it would be much easier and much of my traffic is not logged in.

I'm pretty positive this will appear on the front end as I need it to, the real question is whether or not it will cache anything when I keep disabling it. But of course I would be interested in any other potential problems doing this.

For example:

  • User 1 (not logged in)- Executes page and creates cache
  • User 2 (logged in)- Executes page- caching is disabled
  • User 3 (not logged in)- Will this load from the cache?


Haven't used Smarty in a few years but here is my take, unless your logged in and anonymous/logged out users have completely different views, I would factor out the logged in view that changes in dynamic blocs, as per the manual reccomendations.

There is a pluggin to control the cache but quite buggy I don't recommend it.

Also, many confuse compilation and caching, if you want 100% caching, the $force_compile directive may do what you want but is not recommended for production sites as it does add a perfomance hit. ­

This man page may also help you do what you are aiming for.

Good luck friend! :o)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜