(should anyone else read this post...)
I think my confusion may have stemmed directly from the (v2.2) 
documentation....  
http://turbogears.readthedocs.org/en/rtfd2.2.2/main/RequestFlow.html

"to use a middleware before the TurboGears stack is processed you can wrap 
the application returned by make_base_app function:

    app = make_base_app(global_conf, full_stack=True, **app_conf)
    app = MyMiddleware(app)
    return app

To use a middleware that is TurboGears specific and wants to have the full 
TurboGears stack available (session, authentication, database, etc...) you 
can pass the middleware class to the make_base_app and it will be created 
wrapping the application:

    app = make_base_app(global_conf, full_stack=True, 
wrap_app=MyMiddleware, **app_conf)
    return app


>From the docs, I assumed that using the latter (ie by using wrap_app) my 
custom middleware would be wrapped inside of the stack -- and hence have 
the access.

Thank you very much for the clarification, Alessandro.  I'll have a look to 
see if `register_hook` can do the job.


Many thanks,
Rob 



On Friday, 2 August 2013 10:48:12 UTC+1, Alessandro Molina wrote:
>
> On Fri, Aug 2, 2013 at 10:44 AM, Rob <[email protected] 
> <javascript:>>wrote:
>
>>
>> I'm having trouble understanding how I can get access to the tg cache and 
>> I'm getting a `TypeError No object (name: cache)` -- I'm tied to TG v2.2 
>> for the time being...
>>
>>
> As stated in my previous email the TurboGears context is not available 
> outside of the turbogears application.
> As your middleware is wrapping around the application is called before the 
> application, and so the context is not available.
> The context includes the cache, so tg.cache is not available inside a 
> middleware. WSGI middleware should not make the assumption that they are 
> running inside TG as they are actually running before TG. 
>
> If you really need to use tg.* objects you are limited to using 
> controller_wrappers which are available also in 2.2. Look at 
> http://turbogears.readthedocs.org/en/development/reference/reference.html#tg.configuration.AppConfig.register_hookif
>  you want to see an example.
>
> Otherwise you are bound to environ['beaker.cache'] which is plain WSGI 
> and doesn't require any TG feature.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to