jeudi 8 septembre 2016

How to handle caching for data coming from NuGet packages

I have this particular pattern for communicating with services from a ASP.NET MVC website.

  • Each service that the website communicates with has its own NuGet service package.
  • Each service package has a business layer, ISomeServiceBusiness that gets injected using Dependency Injection to my Controllers.

So for example I can call someServiceBusiness.GetSomeData(x);from my controller to get data from a service.

But now the question is, where do I handle caching? Should I define some cache interface for the packages so that they can do the caching themselves? Or should I create some kind of "Package Acccess Layer" in my MVC project that calls services and handles caching? Or simply cache everything within the Controller?

I have a feeling that there's a known software architecture pattern for this. Most people talk about caching in the DAL (Data Access Layer) but that means I'd have to pass a cache object to the packages.

Some ideas that I thought of:

  1. Implement generic ICache interface for the packages and have the MVC project define what kind of caching mechanism should be used (memcache, redis, etc.), and then pass the cache object to the packages.
  2. Do the caching in the Controllers.
  3. Create a layer in my MVC project that communicates with service packages, and have it cache the data returned. (Doesn't feel right)

What is your opinion? Thanks.

Aucun commentaire:

Enregistrer un commentaire