Previously Wichert Akkerman wrote:
> I have what I suspect is a reasonably common setup with a repoze.who
> middleware for authentication, followed by transaction, routes, 
> session, cache, registry manager and pylons middlewares.
> 
> In some cases you want to use a cache in authentication middleware
> to prevent a SQL server hit on every request. Not completely
> unexepctedly that immediately aborts on "No object (name: cache) has
> been registered for this thread". Strangely enough moving the
> registry and cache middlewares up to be before the auth middleware
> did not help: I got the exact same error.
> 
> Is there some magic in pylons that I'm missing?

Of course just after sending this I figured out what it was. In case
this is useful for others: I solved this by adding a tiny bit of
middleware which registers the beaker cache.

class CacheRegisteringApp(object):
    def __init__(self, app):
        self.app=app

    def __call__(self, environ, start_response):
        from pylons.util import PylonsContext
        import pylons

        context = PylonsContext()
        context.cache = environ["beaker.cache"]
        environ["2s4u.context"] = context

        registry = environ['paste.registry']
        registry.register(pylons.cache, context.cache)

        return self.app(environ, start_response)


Wichert.

-- 
Wichert Akkerman <wich...@wiggy.net>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.

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

Reply via email to