No having it as a global is much better then in a middleware, because
setting up the global happens only once at process start-up time, but
the middleware is called in every request. In the middleware you add
it to the environment, which is again something that's newly created
for every request, but the app-globals are only created once at
process startup and remain for the duration of the process. You only
want to put something in the per-request environment if it is
something that's specific to that request, like the query string.
A static global value like a reference to cache manager (the reference
to that object doesn't change afte it's set up at startup) should not
be in the middleware.

This is a simple design concept, just like the concept of not
referencing private attributes (e.g. obj._prop) outside the definition
of obj's Class (where it would be self._prop which is ok).

On Jan 8, 10:51 am, Ben Bangert <[email protected]> wrote:
> On Jan 8, 2009, at 4:12 AM, Tycon wrote:
>
> > What does it actually do that we need to have a middleware for it that
> > executes in every request ?
>
> Exactly what you said next.
>
> > Does it do anything besides insert a reference to some "Cache Manager"
> > into the environment ?
>
> Nope, that's it.
>
> > If so, then why not have the Cache Manager as a regular global
> > object ?
>
> That'd work as well. Either way, the same amount of code is going to  
> run to add it to the globals.
>
> > In fact,  when using memcache there is only a single giant cache, so
> > then we don't even need a cache manager.
>
> Well, if you want the locking and duplicate creation prevention  
> checking code, and such, then you'd want the cache manager, rather  
> than just using memcached directly. That's really what the cache  
> manager is doing, and why you'd want to use it.
>
> You're right that it doesn't need to be middleware, its quite likely I  
> went middleware-crazy on that. Part of the reason for putting it there  
> rather than inside the PylonsApp code that sets up the globals was so  
> that it'd be easier to remove if you didn't want to use it, though a  
> flag passed to PylonsApp could do that as well.
>
> Would a flag to turn it off be preferable to just removing that line  
> from middleware.py?
>
> Cheers,
> Ben
>
>  smime.p7s
> 3KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to