# create session object session = Session() # query some records users = session.query(User).all() # expire all objects session.expire_all() # query records again, this will hit the database users = session.query(User).all()
# create session object session = Session() # query a record user = session.query(User).get(1) # expire the record session.expire(user) # access a property on the record, this will hit the database user.nameIn this example, we query a single record from the User table using its primary key. We then call the `expire` method on the record to remove it from the session cache. Finally, we access one of the record's properties (name), which will hit the database to fetch the updated value.