强制在身份映射之外执行sqlalchemy ORM get() [英] Forcing a sqlalchemy ORM get() outside identity map

查看:485
本文介绍了强制在身份映射之外执行sqlalchemy ORM get()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

get()方法在SQLAlchemy的ORM中是特殊的,因为它在向数据库发出SQL查询之前尝试从身份映射返回对象(请参见

The get() method is special in SQLAlchemy's ORM because it tries to return objects from the identity map before issuing a SQL query to the database (see the documentation).

这对性能非常有用,但是可能会导致分布式应用程序出现问题,因为一个对象可能已被另一个进程修改,因此本地进程无法知道该对象是否脏了,并将继续从该对象中检索过时的对象.调用get()时的身份映射.

This is great for performance, but can cause problems for distributed applications because an object may have been modified by another process, so the local process has no ability to know that the object is dirty and will keep retrieving the stale object from the identity map when get() is called.

问题

如何强制get()忽略身份映射并每次都向数据库发出调用?

How can I force get() to ignore the identity map and issue a call to the DB every time?

示例

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆