How to Disable SQLalchemy Caching

How to disable SQLAlchemy caching?

The usual cause for people thinking there's a "cache" at play, besides the usual SQLAlchemy identity map which is local to a transaction, is that they are observing the effects of transaction isolation. SQLAlchemy's session works by default in a transactional mode, meaning it waits until session.commit() is called in order to persist data to the database. During this time, other transactions in progress elsewhere will not see this data.

However, due to the isolated nature of transactions, there's an extra twist. Those other transactions in progress will not only not see your transaction's data until it is committed, they also can't see it in some cases until they are committed or rolled back also (which is the same effect your close() is having here). A transaction with an average degree of isolation will hold onto the state that it has loaded thus far, and keep giving you that same state local to the transaction even though the real data has changed - this is called repeatable reads in transaction isolation parlance.

http://en.wikipedia.org/wiki/Isolation_%28database_systems%29

How to disable caching correctly in Sqlalchemy orm session?

SQLAlchemy doesn't cache on itself. Unless you explicitly implemented a cache, like this one.

Pass echo=True to your sessionmaker and look into the logging output.

Sqlalchemy returns stale rows?

Edit: Adding commit() before reading did the trick, as per eggyal's explanation.

self._session.commit()
self._session.query(Automatic).\
filter(Automatic.do_when <= time()).\
limit(limit).\
all()


Related Topics



Leave a reply



Submit