Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache solution for Dapper when using stored procedures (MSSQL)

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.

like image 351
Tomasito Avatar asked Feb 13 '13 21:02

Tomasito


People also ask

Can stored procedure be cached?

When a stored procedure is executed it is optimized and compiled and the query plan is placed in procedure cache. Procedures remain in cache for other users, as long as there is space.

Does dapper support stored procedures?

Using stored procedures with Dapper can be a great way to take advantage of the strengths of the database while reducing complexity of your code.

Does dapper cache?

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 is SQL Server procedure cache?

The procedure cache is part of the larger memory pool for SQL Server. Starting with SQL Server 7.0, individual parts of the memory pool are. dynamically controlled by SQL Server with no documented option for the DBA to. specifically configure a percentage of the memory pool just for the procedure.


1 Answers

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.

like image 71
Marc Gravell Avatar answered Sep 30 '22 00:09

Marc Gravell