jojacafe
2/22/2017 - 11:19 AM

Api Rest Cache https://msdn.microsoft.com/es-es/communitydocs/web-dev/webapi/implementando-cache

// GET: api/Users/5
[Route("api/v1/users/{id}")]
[ResponseType(typeof(AspNetUsers))]
public async Task<HttpResponseMessage> GetAspNetUsers(string id)
{
    AspNetUsers data = await db.AspNetUsers.FindAsync(id);

    if (data == null)
    {
        var httpResponseMessageNotFound = Request.CreateResponse(HttpStatusCode.NotFound);
        httpResponseMessageNotFound.Headers.CacheControl = new CacheControlHeaderValue()
        {
            MaxAge = TimeSpan.FromMinutes(AppGlobal.CacheMaxAge)
        };

        return httpResponseMessageNotFound;
    }

    var httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, data);
    httpResponseMessage.Headers.CacheControl = new CacheControlHeaderValue()
    {
        MaxAge = TimeSpan.FromMinutes(AppGlobal.CacheMaxAge)
    };

    return httpResponseMessage;
}
public static double CacheMaxAge
{
    get
    {
        double data = 0;
        string setting = System.Configuration.ConfigurationManager.AppSettings["CacheMaxAge"];

        double.TryParse(setting, out data);

        return data;
    }
}