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)
        {
            if (isServiceCachable && keyBuilder.CanJsonBeCached)
            {
                JsonUnit unit = new JsonUnit(keyBuilder.ServiceId, keyBuilder.CacheKey, json, absoluteUri,
                                             (DateTime.Now - startTime).TotalMilliseconds);

                try
                {
                    WebCache.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, absoluteUri);
                }
            }
        }