I use dapper to return objects from my database as IEnumerable. As default dapper has buffer setting set to true.
How does this work?
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?
In SQL Server, the buffer cache is the memory that allows you to query frequently accessed data quickly. When data is written to or read from a SQL Server database, the buffer manager copies it into the buffer cache (aka the buffer pool).
Dapper caches information about every query it runs, this allow it to materialize objects quickly and process parameters quickly. The current implementation caches this information in a ConcurrentDictionary object. What exactly does this mean?
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:
false
: will iterate items as they are recieved/consumed - basically, an iterator-block around an IDataReader
true
(the default): the data is fully consumed into a List<T>
before it hands it back to you 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With