查询缓存如何提高 nHibernate 的性能?

发布于 2024-08-23 21:48:34 字数 38 浏览 4 评论 0原文

查询缓存如何工作以及如何提高 nHibernate 中的性能?

How does query caching works and how does it improves performance in nHibernate?

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

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

发布评论

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

评论(3

合约呢 2024-08-30 21:48:34

当缓存查询时,NHibernate 将缓存查询结果的实体 ID。

非常重要的是,它不缓存实体本身 - 只缓存它们的 ID。这意味着您几乎肯定希望确保这些实体也设置为可在二级缓存中缓存。否则,NHiberate 将从查询缓存中获取实体的 ID,但随后被迫前往数据库获取实际实体。这可能比一开始就访问数据库的成本更高!

同样重要的是:查询是根据其确切的 SQL 和参数值进行缓存的。其中任何一个的差异都意味着数据库将受到影响。因此,您可能只想缓存那些输入变化不大的查询。

When a query is cached, NHibernate will cache the IDs of the entities resulting from the query.

Very importantly, it does not cache the entities themselves - only their IDs. This means that you almost certainly want to ensure that those entities are also set to be cachable in your second level cache. Otherwise, NHiberate will get the IDs of the entities from the query cache, but then be forced to go to the database to get the actual entities. That could be more costly than just going to the database in the first place!

Also important: queries are cached based on their exact SQL and parameter values. Any differences in either of those will mean that the database will be hit. So you probably only want to cache those queries that have little variance in their inputs.

毁我热情 2024-08-30 21:48:34

当您启用缓存时,当您执行查询时,nHibernate 会将查询结果存储在内部某处。当您尝试再次使用相同的参数执行查询时,它将从缓存中获取结果,而不是从数据库中获取结果,当然它要快得多!但请注意其他应用程序可以在后台修改数据库!但nHibernate可以更新缓存。

When you enable the caching the nHibernate will store query results somewhere inside when you execute query. When you try to execute query with SAME parameters again it will get results from cache, not from database, and of course it is much faster! but beware that other apps can modify database in background! But nHibernate can update caches.

迷离° 2024-08-30 21:48:34

通过使用它,nHibernate 不需要访问数据存储,它可以访问缓存中的内容。

By using it nHibernate doesn't need to access the Data store it access whats in the cache.

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