On Wed, Dec 08, 2010 at 08:29:36PM +0100, Juliusz Gonera wrote:
> I'm using beaker_cache to cache results of some actions. The problem
> is, their result (the template used) depends sometimes on the domain
> which is used in the request (the same application is available
> under different domains).
> 
> Right now I have something like this:
> 
> @beaker_cache(expire=600, query_args=True)
> def group(self, id, portal=request.environ.get('HTTP_HOST', '')):

That's not going to work -- as you've discovered.

> The portal argument is there just to force beaker_cache to include
> the domain in key generation (I didn't find another way). This
> however, does not work as expected.
> 
> I try to access the page first using domain1, then domain2. If I do
> raise Exception at the beginning of the action I can see that for
> domain1 key_dict = {'id': u'1', 'portal': 'domain1'}, but for
> domain2 key_dict is also {'id': u'1', 'portal': 'domain1'} ! Why is
> it like that?

The default value for function arguments is computed during import time.
Pylons imports the controllers dynamically during request processing,
and that's the only reason it even works -- but it uses the HTTP_HOST
value of the first request that triggered the import.

I don't know the correct solution; you might need to write your own
cache decorator.  http://pypi.python.org/pypi/decorator is useful for
those.

Marius Gedminas
-- 
We don't really understand it, so we'll give it to the programmers.

Attachment: signature.asc
Description: Digital signature

Reply via email to