Cache solution for Dapper when using stored procedures (MSSQL)

asp.net-mvc-3 c#-4.0 dapper sql-server-2008

Question

I'm using Dapper mainly for calling stored procedures in the database MSSQL 2008 R2.I do not have classes that map to database tables. Most of the data ends up in IEnumerable <Dynamic> and is transmitted to the grid on the screen.

Is there a ready to use solution for data buffering that I could use? (I need to use it on the MVC).

The data in the database are both static and dynamic in nature.I use the repository model to access the data.

Expert Answer

Dapper doesn't include any inbuilt data caching features (although it uses extensive caching internally for the meta-programming layer): it aims itself squarely at the ADO.NET stuff - however, you could use pretty much any off-the-shelf caching component, including the HTTP runtime cache (HttpContext.Current.Cache), or the newer ObjectCache etc implementations. Because these just take objects, it should work fine.

If you are using a distributed cache (maybe via app-fabric, redis, or memcached) then you'd need the data to be serializable. In that scenario, I would strongly suggest using formal POCO types for the binding, rather than the dynamic API. As an example, in-house we use dapper to populate POCOs that are annotated with protobuf-net markers for serialization, and stored via BookSleeve to redis. Which sounds more complicated than it actually is.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why