防止MySQL中的查询缓存 [英] Preventing queries caching in MySQL

查看:115
本文介绍了防止MySQL中的查询缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the tomcat connection pool via JNDI resources.

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数据库.

The database is a MySQL one.

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

When I select some informations, for example a product list, the same list is displayed also after a product insertion or deletion.

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

How prevent this? In this case, I would to see the updated list.

编辑

query_cache_size为0,query_cache_type为ON.

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

So, where could be the issue? Why does the query caching happen?

编辑

我阅读了有关"RESET QUERY CACHE"和"FLUSH TABLES"的信息.

I read about "RESET QUERY CACHE" and "FLUSH TABLES".

它们之间有什么区别?

What is the difference between them?

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

By using one of them, may there be issues in an auction/e-commerce scenario?

推荐答案

如果事务隔离级别

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 ]

如果要查看数据库的最原始"状态,请使用 READ COMMITTED 隔离级别或锁定阅读:

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;

您可以通过其Resource@defaultTransactionIsolation属性在Tomcat 中设置默认事务隔离级别.

You can set the default transaction isolation level in Tomcat via its Resource@defaultTransactionIsolation attribute.

这篇关于防止MySQL中的查询缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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