防止MySQL中的查询缓存 [英] Preventing queries caching in 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 如果要查看数据库的最原始"状态,请使用 If you want to see the "freshest" state of the database, use either the
您可以通过其 You can set the default transaction isolation level in Tomcat via its 这篇关于防止MySQL中的查询缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
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
隔离级别或锁定阅读:READ COMMITTED
isolation level or a locking read:SELECT * FROM t LOCK IN SHARE MODE;
Resource@defaultTransactionIsolation
属性Resource@defaultTransactionIsolation
attribute.