在 cfquery 中使用 cachedwithin 属性
当您在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它不仅仅是名称——它是您正在运行的确切查询。
如果您在应用程序中的其他任何地方调用相同的查询,并且在第一次查询后的半天内,您将获得缓存的版本。但这些将访问数据库以获取新数据:
是的,它确实考虑了一个变量。如果您使用
cfqueryparam
——您应该这样做——您的数据库将缓存查询计划,但即使使用cachedwithin
,每个查询从查询缓存的角度来看,更改的参数将被视为不同的参数。请注意,这意味着如果您在使用不同参数运行多次的查询上使用cachedwithin
,则缓存命中率较低的查询会淹没您的查询缓存。It's not only the name -- it's the exact query you're running.
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:
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 usingcachedwithin
, each query with a changed parameter will be treated as different from a query caching perspective. Note that this means if you usecachedwithin
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.来自 http://help.adobe.com/en_US/ColdFusion /9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html
那么这些是“决定是否是相同查询”变量的“键”
?是的,只要您使用
From http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html
So those are the 'keys' that "decide if it is the same query"
variable? yes, as long as you use
<cfqueryparam>