How to use caching with WCF

I am developing a WCF that will return JSON data. The method will take a parameter and return data from the database.

If the load on WCF is high, it would be great to use some caching to avoid having to constantly dig into db.

EDIT: The method will return the last elements. Thus, the method should return the same response for the entire request, which provides the same time interval as the parameter.

How can this be done effectively? I read litle about caching a basic web HTTP service, but I'm not sure if this is the best solution.

Thank you very much.

+4
source share
2 answers

Personally, I would like to make my WCF services ready for the session and store my caches in the session. A compromise always depends on how static the data is and how much data needs to be torn down.

For very static data, I can cache the duration of the session or until the data has changed (determining whether another user has changed my cached session data is a different story). For very dynamic data, it’s hard for me to trust the cache for longer than a few minutes (which is not yet completely safe).

The question is, what are you talking about client side caching or server side caching? So, are you trying to cache the data sets on the client or just cache on the web server that pulled the data set from the database server?

If you're talking about client caching, you can cache cookies, cache javascript variables, use HTTP caching, or the aforementioned caching mechanism for HTML 5 applications.

All about the right tool to work, although in this case there is no hammer;)

+1
source

You can use HTTP Cache Control: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

Or HTML 5 application cache: http://www.html5rocks.com/en/tutorials/appcache/beginner/

How will your customers use the WCF service? Through jQuery AJAX queries? Standard GET requests?

0
source

Source: https://habr.com/ru/post/1386356/


All Articles