Friday, November 11, 2016

Caching

Cache Output



Install-Package Strathweb.CacheOutput.WebApi2

1
[CacheOutput(ClientTimeSpan = 600, ServerTimeSpan = 600)]

In my example,  I am telling it to cache the results for both client and server-side for 600 sec (10 min).  There isn’t a whole lot of science behind choosing 10 minutes, and I could have written some fancy code to figure out when my scheduled job ran last but I wanted to keep it simple.

Example

using WebApi.OutputCache.V2;

public class CacheTestController : ApiController
    {
        [HttpGet]
        [CacheOutput(ClientTimeSpan = 100, ServerTimeSpan = 100)]
        public string CacheTest123()
        {
            Thread.Sleep(5000);
            return "google";
        }
 
        [HttpGet]
        public string CacheTest1234()
        {
            Thread.Sleep(5000);
            return "google";
        }
    }

CS Events