gpt4 book ai didi

mysql - 防止在 MySQL 中缓存查询

转载 作者:可可西里 更新时间:2023-11-01 07:20:32 25 4
gpt4 key购买 nike

我正在通过 JNDI 资源使用 tomcat 连接池。

context.xml中:

<Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
username="myusr" password="mypwd" driverClassName="com.mysql.jdbc.Driver"
maxActive="1000" maxIdle="100" maxWait="10000"
url="jdbc:mysql://localhost:3306/mydatabase"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" />

web.xml 中:

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

数据库是MySQL。

当我选择一些信息时,例如产品列表,在插入或删除产品后也会显示相同的列表。

如何防止这种情况?在这种情况下,我会看到更新后的列表。

编辑

query_cache_size 为 0,query_cache_type 为 ON。

那么,问题出在哪里?为什么会发生查询缓存?

编辑

我阅读了“RESET QUERY CACHE”和“FLUSH TABLES”。

它们有什么区别?

使用其中之一,在拍卖/电子商务场景中是否会出现问题?

最佳答案

根据 Consistent Nonlocking Reads 记录:

If the transaction isolation level is REPEATABLE READ (the default level), all consistent reads within the same transaction read the snapshot established by the first such read in that transaction. You can get a fresher snapshot for your queries by committing the current transaction and after that issuing new queries.

[ deletia ]

If you want to see the “freshest” state of the database, use either the READ COMMITTED isolation level or a locking read:

SELECT * FROM t LOCK IN SHARE MODE;

您可以在 Tomcat 中设置默认的事务隔离级别 via its Resource@defaultTransactionIsolation attribute .

关于mysql - 防止在 MySQL 中缓存查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17025412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com