短小精悍的缓冲区/高速缓存的说明 [英] Explanation of dapper buffer/cache

查看:139
本文介绍了短小精悍的缓冲区/高速缓存的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用短小精悍从我的数据库为IEnumerable返回对象。
由于默认短小精悍具有缓冲设置为true。

I use dapper to return objects from my database as IEnumerable. As default dapper has buffer setting set to true.

这是如何工作的?

如果短小精悍的高速缓存中的第一个查询,然后从内存获取的对象。

If dapper cache the first query and then get the objects from memory.

如果有人编辑/删除/表中添加行,会发生什么。必须为此再次查询短小精悍重新缓存所有的数据?

What happens if someone edit/delete/add rows in the table. Must dapper recache all data again for this query?

推荐答案

的缓冲区是无关的缓存。 hardy中不包括任何种类的数据缓存中(虽然它确实有关系到它如何处理命令,即该命令串,这种类型的参数,以及这种类型的实体的高速缓存 - 具有下列相关动态生成的方法来配置命令和填充物)。

The buffer is unrelated to cache. Dapper does not include any kind of data-cache (although it does have a cache related to how it processes commands, i.e. "this command string, with this type of parameter, and this type of entity - has these associated dynamically generated methods to configure the command and populate the objects").

这是什么开关真正的意思是:

What this switch really means is:


  • :将迭代的项目,因为他们收到/消费 - 基本上,围绕一个迭代器块的IDataReader

    • 减:你只能重复一次(除非你很高兴重新运行查询)

    • 加:您可以遍历巨大查询(数百万行),不都在内存中一次需要他们 - 因为你永远只真正关注的当前行所产生

    • 加:你并不需要等待数据的末尾开始迭代 - 只要它至少有一个行,你去好

    • 减:连接在使用中,而你迭代,从而导致已经有连接上一个开放阅读器(或任何确切的措辞)错误,如果你尝试调用一个其他命令按行(这可以通过MARS可以减轻)

    • 减:因为消费者可以做他们每个项目想要的任何东西(这可能需要几分钟每行,如果他们正在做一些复杂的),命令/读者可能开放供更长

    • false: will iterate items as they are recieved/consumed - basically, an iterator-block around an IDataReader
      • minus: you can only iterate it once (unless you are happy to re-run the query)
      • plus: you can iterate over immense queries (many millions of rows), without needing them all in-memory at once - since you're only ever really looking at the current row being yielded
      • plus: you don't need to wait for the end of the data to start iterating - as soon as it has at least one row, you're good to go
      • minus: the connection is in-use while you're iterating, which can lead to "there is already an open reader on the connection" (or whatever the exact wording is) errors if you try to invoke other commands on a per-row basis (this can be mitigated by MARS)
      • minus: because the consumer can do anything they want per-item (it could take minutes per row, if they are doing something complex), the command/reader might be open for longer

      • 加:只要你喜欢,你可以遍历它多次

      • 减去:如果查询是巨大的,装载他们都到内存(在列表中)可能是昂贵的/不可能

      • 减去:如果查询较大,有可能出现明显的延迟,同时它收集的最后一行

      • 加:一旦你的数据,命令完成了 - 所以这一点,随后的操作之间没有冲突

      • 加:一旦你得到的数据,命令已经发布的任何资源(锁等),所以你在服务器上的影响微乎其微。

      大多数查询只返回数据适量的(比如,小于100条记录),所以我们很高兴的是,默认的(真正)给出了最恰当的行为对于大多数场景。但是,我们向您提供的选项来满足不同的使用场景。

      Most queries only return a moderate amount of data (say, less than 100 records), so we're happy that the default (true) gives the most appropriate behavior for most scenarios. But we make the option available to you, to cater for different usage scenarios.

      这篇关于短小精悍的缓冲区/高速缓存的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆