public void SaveJson(JsonUnit jsonUnit)
        {
            SqlCommand cmd = GetProcedure("usp_pholio_insert_json");
            cmd.Parameters.AddWithValue(ServiceId, jsonUnit.ServiceId);
            cmd.Parameters.AddWithValue(CacheKey, jsonUnit.CacheKey);
            cmd.Parameters.AddWithValue("json", jsonUnit.Json);
            cmd.Parameters.AddWithValue("url", jsonUnit.Url);
            cmd.Parameters.AddWithValue("duration_ms", jsonUnit.DurationInMs);

            ExecuteNonSelectCommand(cmd);
        }
 public void AddJson(JsonUnit jsonUnit)
 {
     if (jsonUnit.IsJsonOk())
     {
         if (UseDatabaseCache)
         {
             DatabaseCacheManager.SaveJson(jsonUnit);
         }
         AddToWebCache(jsonUnit);
     }
 }
        private static void AddToWebCache(JsonUnit jsonUnit)
        {
            if (UseInMemoryCache)
            {
                Dictionary<string, byte[]> d = GetDictionary(jsonUnit.ServiceId);

                // Lock to prevent thread collisions, in .Net4 use ConcurrentDictionary
                lock (d)
                {
                    if (d.ContainsKey(jsonUnit.CacheKey) == false)
                    {
                        d.Add(jsonUnit.CacheKey, jsonUnit.Json);
                    }
                }
            }
        }
        private void CacheJson(byte[] json, string serviceAction, string serviceParameters, HttpRequestBase request)
        {
            string absoluteUri = request.Url.AbsoluteUri;

            JsonUnit unit = new JsonUnit(serviceAction, serviceParameters, json, absoluteUri,
                                             (DateTime.Now - _startTime).TotalMilliseconds);

            try
            {
                _jsonCache.AddJson(unit);
            }
            catch (Exception ex)
            {
                /* Suppress race condition where same JSON added twice 
                     * but log exception in case key is not unique */
                ExceptionLogger.LogException(ex, "Global.asax");
            }
        }