Caching Data

In this section, we are going to cache requests for getting a question. At the moment, the database is queried for each request to get a question. If we cache a question and can get subsequent requests for the question from the cache, this should be faster and reduce the load on the database. We will prove this with load tests.

Load testing the current implementation

Before we implement caching, we are going to load test the current implementation of getting a single question using the following steps:

  1. Let's start our REST API by pressing “F5” in Visual Studio.

  2. Now, we can load test the current implementation using WebSurge. Let's set the request URL path to /api/questions/1 and change the duration to “30” seconds with “5” threads.

  3. Start the test. When the test has finished, we'll get our results:

Get hands-on with 1400+ tech skills courses.