Hey Shihab,

what I did is create a class that extends sfViewCacheManager,
and override the generateCacheKey() method like so:

public function generateCacheKey($internalUri, $hostName = '', $vary =
'', $contextualPrefix = '')
{
    $key = parent::generateCacheKey($internalUri, $hostName, $vary,
$contextualPrefix);
    return $this -> customizeKey($key);
}

and the customize method looks like this:

protected function customizeKey($key)
{
    $user = $this -> getContext() -> getUser();

    $new_key[] = $key;
    $new_key[] = "brand".$user -> getCurrentBrandId();
    $new_key[] = $user -> isAdmin() ? "admin" : "dealer";
    $new_key[] = $user -> isAuthenticated() ? "logged-in" : "logged-
out";

    return implode("/", $new_key);
}

That way I have all the parameters that determine who needs different
caches in one method.

Then all you need to do is configure factories.yml to use that class:

all:
  view_cache_manager:
    class: MyViewCacheManager


That's it. Good luck,
Daniel


On Jan 24, 4:06 am, Shihab KB <shiha...@gmail.com> wrote:
> Hi,
>
> Thanks for your answer.
>
> Can you tell me how can I do that? Do u have any reference links? I am
> not much familiar.
>
> Can you tell me with one example. I am really thankful to you.
>
> regards
> Shihab
>
> On Jan 23, 12:01 am, Richtermeister <nex...@gmail.com> wrote:
>
> > I believe you can make the cache key whatever you want... so in your
> > case just module/action and whatever neccessary parameter, but not
> > user id.
> > I've used this in reverse, where I had the same url for everybody, but
> > depending on the login status and session id I'd generate a unique
> > cache key, since the content chanced per user.
>
> > Daniel
>
> > On Jan 21, 5:44 am, Gabriel Petchesi <pghora...@gmail.com> wrote:
>
> > > Symfony builds up the cache key based upon the URL in case of action or
> > > parameters (for partials, components).
>
> > > I'm not sure if you can override the cache key within the action so my
> > > suggestion is to create a simple action with a template and within
> > > that template include a component that will be cached.
>
> > > For that component set up the cache_key value however you want, it could 
> > > be
> > > any of the following:
> > > include_component('service', 'provider', array('sf_cache_key' =>
> > > md5($service.$ver.$lang)))
> > > or a concatenated string with the important values
> > > include_component('service', 'provider', array('sf_cache_key' =>
> > > $service.$ver.$lang)))
> > > or by specifying exactly the elements you want to be used for caching,
> > > symfony caching will compute a hash based on that:
> > > include_component('service', 'provider', array('service' => $service, 
> > > 'ver'
> > > => $ver, 'lang' => $lang));
>
> > > For improved speed you could look into something like the sfSuperCache to
> > > avoid loading the framework altogether, not sure if it works
> > > for Symfony 1.4.
>
> > >     gabriel

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to