Search code examples
pythonauthorizationpyramidwsgiuser-registration

In Pyramid how should I keep a list of users and allow adding more with a registration view?


I have an application that implements authorization as described here: http://michael.merickel.org/projects/pyramid_auth_demo/

In the examples the users are kept in a global variable called USERS = {} that I have in a module called config.py

USERS = {}

The problem is that I have a registration view that adds new users to USERS with this code:

config.USERS["newUser"] = User("newUser")

but as WSGI server handles the requests config.USERS in some cases does not contain the newly added user by the registration process.

How should I keep the list of users so is updated by the registration process and accessed in an updated way by all other requests?


Solution

  • If you really need to keep Users list in memory you should write function updating this list and call it when new User is registered.

    If I were you I would rather create global function getting Users from database and cache it for some time using for example Beaker Cache and when new User is added I would invalidate this cache region. To get more details please refer to the Beaker Cache manual.