此内容没有您所选择的语言版本。

Chapter 4. Result Set Caching


4.1. User Query Cache

User query result set caching will cache result sets based on an exact match of the incoming SQL string and PreparedStatement parameter values if present. Caching only applies to SELECT, set query, and stored procedure execution statements; it does not apply to SELECT INTO statements, or INSERT, UPDATE, or DELETE statements.
End users or client applications explicitly state whether to use result set caching. Do this by setting the JDBC ResultSetCacheMode execution property to true (by default it is set to false).
		Properties info = new Properties();

...

info.setProperty("ResultSetCacheMode", "true");

Connection conn = DriverManager.getConnection(url, info);
Copy to Clipboard Toggle word wrap
Alternatively, add a Cache Hint to the query.

Note

Note that if either of these mechanisms are used, DV must also have result set caching enabled (it is so by default).
The most basic form of the cache hint, /*+ cache */, is sufficient to inform the engine that the results of the non-update command must be cached.
  
  ...
PreparedStatement ps = connection.prepareStatement("/*+ cache */ select col from t where col2 = ?");
ps.setInt(1, 5);
ps.execute();
...
  
Copy to Clipboard Toggle word wrap
The results will be cached with the default ttl and use the SQL string and the parameter value as part of the cache key. The pref_mem and ttl options of the cache hint may also be used for result set cache queries. If a cache hint is not specified, then the default time to live of the result set caching configuration will be used.
Here is a more advanced example:
  
  /*+ cache(pref_mem ttl:60000) */ select col from t
  
Copy to Clipboard Toggle word wrap
In this example the memory preference has been enabled and the time to live is set to 60000 milliseconds (1 minute). The time-to-live for an entry is actually treated as its maximum age and the entry may be purged sooner if the maximum number of cache entries has been reached.

Important

Each query is re-checked for authorization using the current user’s permissions, regardless of whether or not the results have been cached.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat