在 cfquery 中使用 cachedwithin 属性

发布于 2024-09-05 10:33:52 字数 202 浏览 3 评论 0原文

当您在 cfquery 中使用 cachedwithin 属性时,它如何将查询存储在内存中。它是否仅按您分配给查询的名称存储它?例如,如果在我的索引页面上我缓存一个查询一个小时并将其命名为 getPeople,则不同页面(或同一页面)上具有相同名称的查询将使用缓存的结果,或者它是否使用一些更好的逻辑判断是否是同一个查询?

另外,如果查询中有变量,缓存是否会考虑该变量的值?

When you use the cachedwithin attribute in a cfquery how does it store the query in memory. Does it store it by only the name you assign to the query? For example, if on my index page I cache a query for an hour and name it getPeople will a query with the same name on a different page (or the same page for that matter) use the cached results or does it use some better logic to decide if it is the same query?

Also, if there is a variable in your query does the cache take into account the value of the variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软的没边 2024-09-12 10:33:53

它不仅仅是名称——它是您正在运行的确切查询。

<cfquery name="getPeople" cachedwithin=".5" ...>
select name from employee order by name
</cfquery>

如果您在应用程序中的其他任何地方调用相同的查询,并且在第一次查询后的半天内,您将获得缓存的版本。但这些将访问数据库以获取新数据:

<!--- Different name, same SQL: A new cached query --->
<cfquery name="getEmployees" cachedwithin=".5" ...>
select name from employee order by name
</cfquery>

<!--- Different SQL, same name: Redefining the cached query --->
<!--- Note: As pointed out in comments, it's not really overwriting the old query
      of the same name, but making a new one in the cache. The first one by the
      same name is still in the cache, waiting for eviction. --->
<cfquery name="getPeople" cachedwithin=".5" ...>
select name from employee order by name desc
</cfquery>

是的,它确实考虑了一个变量。如果您使用cfqueryparam——您应该这样做——您的数据库将缓存查询计划,但即使使用cachedwithin,每个查询从查询缓存的角度来看,更改的参数将被视为不同的参数。请注意,这意味着如果您在使用不同参数运行多次的查询上使用 cachedwithin,则缓存命中率较低的查询会淹没您的查询缓存。

It's not only the name -- it's the exact query you're running.

<cfquery name="getPeople" cachedwithin=".5" ...>
select name from employee order by name
</cfquery>

If you invoke this same query anywhere else in your app, you'll get the cached version if it's within half a day of the first query. But these will hit the database for fresh data:

<!--- Different name, same SQL: A new cached query --->
<cfquery name="getEmployees" cachedwithin=".5" ...>
select name from employee order by name
</cfquery>

<!--- Different SQL, same name: Redefining the cached query --->
<!--- Note: As pointed out in comments, it's not really overwriting the old query
      of the same name, but making a new one in the cache. The first one by the
      same name is still in the cache, waiting for eviction. --->
<cfquery name="getPeople" cachedwithin=".5" ...>
select name from employee order by name desc
</cfquery>

And yes, it does take a variable into account. If you use cfqueryparam -- which you should be doing -- your database will cache the query plan, but even using cachedwithin, each query with a changed parameter will be treated as different from a query caching perspective. Note that this means if you use cachedwithin on a query that runs many times with different parameters, you'll be flooding your query cache with queries that have low cache hit rates.

雨落星ぅ辰 2024-09-12 10:33:53

来自 http://help.adobe.com/en_US/ColdFusion /9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html

要使用缓存数据,当前查询
必须使用相同的 SQL 语句、数据
来源、查询名称、用户名、
密码。

那么这些是“决定是否是相同查询”变量的“键”

?是的,只要您使用

From http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html

To use cached data, current query
must use same SQL statement, data
source, query name, user name,
password
.

So those are the 'keys' that "decide if it is the same query"

variable? yes, as long as you use <cfqueryparam>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文