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?
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 anIDataReader
true
(the default): the data is fully consumed into aList<T>
before it hands it back to youMost 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.