public void ProcessRequest(HttpContext context)
        {
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType = "application/json";

            string bookTitle = context.Request.QueryString[Literals.BookTitle];
            string bookAuthor = context.Request.QueryString[Literals.BookAuthor];

            string uri = GetGoodreadsURI(bookAuthor, bookTitle);
            int serverStatusCode = 200;

            int secondsToCacheData = Int32.Parse(keyManager.GetConfigurationByKey(Literals.SecondsToCacheData));
            CacheManager cm = new CacheManager(secondsToCacheData);
            string returnData = cm.GetCacheValue(uri);

            if (null == returnData)
            {
                returnData = GetGoodreadsJSONResponse();
                string responseData = GetResponseFromAPI(uri, out serverStatusCode);
                if (serverStatusCode == 200)
                {
                    returnData = ConvertGoodreadsXMLtoJSON(responseData, returnData);
                }
                cm.InsertToCache(uri, returnData);
            }
            
            context.Response.Write(returnData);
        }
Example #2
0
 public static CacheManager GetCacheManager(int secondsToCacheData)
 {
     if (null == _internalManager)
     {
         lock(_lockObject)
         {
             if (null == _internalManager)
             {
                 _internalManager = new CacheManager(secondsToCacheData);
             }
         }
     }
     return _internalManager;
 }