A simple in memory cache for “business data”.

1 minute read

A simple in memory cache for "business data"

Here is a little project demonstrating a little in-memory data cache using DataSets and serviced components. The demo illustrates how to deal with near data in a smarter way than by just walking up to SQL Server all the time. My "Layers and Tiers" slide deck of the recent tour makes the point that it's a good idea to delegate data access to services which are aware of the temporal character of data (static, near static, dynamic and "hot") and optimize access to that data accordingly. The sample also illustrates a way of implementing proper layering for such a data service: The public interface is a Serviced Components (an alternate public interface could be a web service or whatever else), the internal implementation is a base class providing the caching logic and the resource access is realized by deriving one version for SQL Server access and one of OleDb access from this base class. Creating instances of the concrete implementations is done through a config-driven factory.  -- looser binding towards the "client edge" and tighter binding towards the "backend edge".

The concrete implementation assumes that the "Products" and "Categories" tables in the accessed Northwind database copy are in a read-only replica and assumes that the data will always conveniently fit into memory. The demo shows the perf. difference between the cached and the direct database access versions.

The time difference isn't only due to the caching, though. The sample also shows how to use "connection pooling" to JITA Enterprise Service components using a client side JITA pool. The code for that is included.

Updated:

Leave a Comment