Exemple #1
0
        private ValuesToStore <T> SaveToFirstLevelCacheAndGetSerializedValuesForSecondLevelCache <T>(Dictionary <CacheItemDefinition, T> objects)
            where T : class
        {
            var result = new ValuesToStore <T>();

            foreach (var kvp in objects)
            {
                if (kvp.Value != null)
                {
                    if (SerializationProvider.CanSerialize(kvp.Value.GetType()))
                    {
                        var bytes = SerializationProvider.Serialize(kvp.Value);
                        result.InSecondLevelCache.Add(kvp.Key, bytes);
                        result.InFirstLevelCache.Add(kvp.Key, bytes);
                    }
                    else
                    {
                        var ph = new NonSerializableObjectPlaceHolder();
                        result.InNonSerializableCache.Add(kvp.Key, kvp.Value);

                        byte[] bytes = SerializationProvider.Serialize(ph);
                        result.InSecondLevelCache.Add(kvp.Key, bytes);
                    }
                }
            }

            return(result);
        }
Exemple #2
0
        private void StoreValuesInFirstLevelCacheAndNonSerializableCache <T>(ValuesToStore <T> valuesToStore)
        {
            foreach (var kvp in valuesToStore.InFirstLevelCache)
            {
                FirstLevelCache.Set(kvp.Key.Key, kvp.Value, ttl: kvp.Key.TimeToLive);
            }

            foreach (var kvp in valuesToStore.InNonSerializableCache)
            {
                NonSerializableCache.Set(kvp.Key.Key, kvp.Value, ttl: kvp.Key.TimeToLive);
            }
        }
Exemple #3
0
 private static void RemoveTtlResultFromValuesToStore <T>(Dictionary <string, TimeToLiveResult> ttlResults,
                                                          ValuesToStore <T> valuesToStore)
     where T : class
 {
     foreach (var ttlResult in ttlResults)
     {
         if (ttlResult.Value.KeyExists)
         {
             valuesToStore.InSecondLevelCache.Remove(valuesToStore.InSecondLevelCache.FirstOrDefault(x => x.Key.Key == ttlResult.Key)
                                                     .Key);
             var nonSerializableKey = valuesToStore.InNonSerializableCache.FirstOrDefault(x => x.Key.Key == ttlResult.Key);
             nonSerializableKey.Key.TimeToLive = ttlResult.Value.TimeToLive;
         }
     }
 }