Пример #1
0
            public static void CacheVariable(string sessionKeyID, string name, object value)
            {
                ConcurrentDictionary <string, object> nameValuePairs = null;

                if (!VariablePoolPreCache.VariablePreCache.TryGetValue(sessionKeyID, out nameValuePairs))
                {
                    nameValuePairs = new ConcurrentDictionary <string, object>();

                    if (!VariablePoolPreCache.VariablePreCache.TryAdd(sessionKeyID, nameValuePairs))
                    {
                        VariablePoolPreCache.CacheVariable(sessionKeyID, name, value);

                        return;
                    }
                }

                if (value == null)
                {
                    nameValuePairs.TryRemove(name, out value);
                }
                else
                {
                    nameValuePairs.AddOrUpdate(name, value, (cName, cValue) => value);
                }
            }
Пример #2
0
        private void RegisterVariableToPool(string name, object value)
        {
            VariablePoolPreCache.CleanCachedVariables(this._SessionKeyID, name);

            byte[] serializedValue;
            Stream forStream = null;

            try
            {
                forStream = new MemoryStream();

                BinaryFormatter binFormater = new BinaryFormatter();
                binFormater.Serialize(forStream, value);

                serializedValue = ((MemoryStream)forStream).ToArray();
            }
            catch (Exception)
            {
                serializedValue = new byte[] { };
            }
            finally
            {
                if (forStream != null)
                {
                    forStream.Close();
                    GC.SuppressFinalize(forStream);
                }
            }

            VariablePoolOperation._Cache.Set(name, serializedValue);
        }
Пример #3
0
        private void UnRegisterVariableFromPool(string name)
        {
            VariablePoolPreCache.CleanCachedVariables(this._SessionKeyID, name);

            // Unregister Variable From Pool Immidiately.
            // Otherwise it will cause cache reload in the same domain call
            VariablePoolOperation._Cache.Set(name, null);
        }
Пример #4
0
        private object GetVariableFromPool(string name)
        {
            object rObject = VariablePoolPreCache.GetCachedVariable(this._SessionKeyID, name);

            if (rObject == null)
            {
                byte[] serializedValue = VariablePoolOperation._Cache.Get(name);

                if (serializedValue != null)
                {
                    Stream forStream = null;

                    try
                    {
                        BinaryFormatter binFormater = new BinaryFormatter();
                        binFormater.Binder = new OverrideBinder();

                        forStream = new MemoryStream(serializedValue);

                        rObject = binFormater.Deserialize(forStream);

                        VariablePoolPreCache.CacheVariable(this._SessionKeyID, name, rObject);
                    }
                    catch (Exception)
                    {
                        // Just Handle Exceptions
                    }
                    finally
                    {
                        if (forStream != null)
                        {
                            forStream.Close();
                            GC.SuppressFinalize(forStream);
                        }
                    }
                }
            }

            return(rObject);
        }