Well when you say "always available", are you *sure*? Do you want it available when serving static resources? If you create a request property then it is lazily calculated when you actually do request it and with reify=True it will cache the result for the request duration. NewRequest subscribers are invoked for *every* request after it has gotten through middleware and tweens, but before Pyramid's router takes over.
Sessions are for tracking state across requests, so you could store the number in the session when they log in. I am of the opinion that sessions are overused and almost anything stored in there is an indicator that your data model is incomplete. There's umpteen ways to store state in Pyramid, starting at global solutions and drilling down into local solutions. It's really dependent on your requirements to determine how to do things within Pyramid. Note that if you just want something to appear in a template, the BeforeRender event is where you should be looking to implement that behavior. It's a good way to handle passing state to a base template. On Mon, Jul 2, 2012 at 10:13 AM, Antonio Beamud Montero <[email protected]> wrote: > Hi all: > I want to have the inbox messages number associated with a user always > available. > What's the best way to do this?. As I can read in documentation, I can > accomplish this with: > > - adding a property to the request with 'set_request_property', like: > > myconf.set_request_property(calculate_user_inbox, 'inbox') > > - Using an event suscriber: > > myconf.add_subscriber('myapp.calculate_user_inbox_suscriber', > 'pyramid.events.NewRequest') > > - Using the beaker session. > > What's the pros and the cons? > > Greetings. > > > -- > 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. > -- 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.
