2

I'm creating a 3-tier Web API application based on the Azure guide here. This has a middle tier and a data tier both in Web API.

So far my application is pretty simple, the middle tier receives a request, translates it to the domain model, passes it to the data tier which performs a CRUD operation which is then passed back and mapped back to a DTO for the client.

Now I'm starting to look at request verification. When a CREATE request comes in to the middle tier it may link to existing entities and so require the following checks:

  1. I need to verify that the linked entities belong to the current user
  2. Check to see if the user already has an 'Active' entity of the same type requested.
  3. Check that the linked entities support the requested entity

To me, calling the data tier for each of these (and there could be multiple in each request) is adding a bit of overhead as I'm going to have to do an additional service call for each one which could add to the request time.

Should data retrieval sit solely in the data tier (I know that sounds obvious...) or can some go in the middle tier? The middle tier will only do retrieval, no manipulation.

Thanks

1 Answer 1

1

The common solution the problems you are describing is to implement a caching policy. Unfortunately, caching is not built into Web API by default. However there are a few solutions already created for this. Here are a few articles that describe how to implement caching in Web API:

http://www.strathweb.com/2012/05/output-caching-in-asp-net-web-api/

http://www.hanselman.com/blog/NuGetPackageOfTheWeekASPNETWebAPICachingWithCacheCowAndCacheOutput.aspx

https://github.com/filipw/AspNetWebApi-OutputCache

2
  • would the caching be done at the middle tier or the data tier? i.e. would the middle service cache the results from the data service or the data tier cache the results from the database?
    – ADringer
    Commented Jun 4, 2016 at 20:10
  • Caching can be implemented at any tier. These particular implementations cache at the presentation tier.
    – Nathan
    Commented Jun 6, 2016 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.