For a while now, in my in-development Pylons web app, I've been experiencing what I thought were cache problems. Every X clicks of the refresh button (usually 5 or 10) the page would revert to an older version. I thought this might be some middleware playing tricks on me... but it wasn't. Well not quite.
I use some custom SQLAlchemy magic in my model to dynamically switch between SQLite databases based on the URL, yet still keep the 'core' database available in the same model namespace. The code to setup the correct SQLAlchemy sessions sits in the __before__ method of lib.base.BaseController. As it turns out, I also need to call session.clear() on my SA session object between requests, as it seems some junk is left around, waiting to trick the unwary programmer.
This problem was solved with the help of Band of None and their new tune, Your Myspace Page.