Пример #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.Width = 550;
            try
            {
                mcache_config = new MemcachedClientConfiguration();
                mcache_config.Servers.Add(new IPEndPoint(IPAddress.Parse(localhost), mcache_port));
                mcache_config.Protocol = MemcachedProtocol.Text;
                mcache_client = new Enyim.Caching.MemcachedClient(mcache_config);

                DataBase_0.Open();
                DataBase_1.Open();
                DataBase_2.Open();
                DataBase_3.Open();
                DataBase_4.Open();
                DataBase_info.Open();
            }
            catch (SqlException)
            {
                MessageBox.Show(
                    "Connection failed. DataBases states:\n" +
                    "\nDataBase #1: " + DataBase_0.State.ToString() +
                    "\nDataBase #2: " + DataBase_1.State.ToString() +
                    "\nDataBase #3: " + DataBase_2.State.ToString() +
                    "\nDataBase #4: " + DataBase_3.State.ToString() +
                    "\nDataBase #5: " + DataBase_4.State.ToString() +
                    "\nDataBase info: " + DataBase_info.State.ToString()
                );
            }
            catch (Exception error) { MessageBox.Show("MainForm_Load: " + error.Message); }
        }
        public MemcachedClientCache(IEnumerable <string> hosts)
        {
            const int defaultPort    = 11211;
            const int ipAddressIndex = 0;
            const int portIndex      = 1;

            this.client = new MemcachedClient();
            var ipEndpoints = new List <IPEndPoint>();

            foreach (var host in hosts)
            {
                var hostParts = host.Split(':');
                if (hostParts.Length == 0)
                {
                    throw new ArgumentException("'{0}' is not a valid host IP Address: e.g. '127.0.0.0[:11211]'");
                }

                var port = (hostParts.Length == 1) ? defaultPort : int.Parse(hostParts[portIndex]);

                var hostAddresses = Dns.GetHostAddresses(hostParts[ipAddressIndex]);
                foreach (var ipAddress in hostAddresses)
                {
                    var endpoint = new IPEndPoint(ipAddress, port);
                    ipEndpoints.Add(endpoint);
                }
            }
            LoadClient(ipEndpoints);
        }
 public MemcachedClientCache(InnerClient.MemcachedClient client)
 {
     if (client == null)
     {
         throw new ArgumentNullException("client");
     }
     this.client = client;
 }
        private void LoadClient(IEnumerable <IPEndPoint> ipEndpoints)
        {
            var config = new InnerClient.Configuration.MemcachedClientConfiguration();

            foreach (var ipEndpoint in ipEndpoints)
            {
                config.Servers.Add(ipEndpoint);
            }

            config.SocketPool.MinPoolSize       = 10;
            config.SocketPool.MaxPoolSize       = 100;
            config.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 10);
            config.SocketPool.DeadTimeout       = new TimeSpan(0, 2, 0);

            this.client = new InnerClient.MemcachedClient(config);
        }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                mcache_config = new MemcachedClientConfiguration();
                mcache_config.Servers.Add(new IPEndPoint(IPAddress.Parse(localhost), mcache_port));
                mcache_config.Protocol = MemcachedProtocol.Text;
                mcache_client = new Enyim.Caching.MemcachedClient(mcache_config);

                DataBase_0.Open();
                DataBase_1.Open();
                DataBase_2.Open();
                DataBase_3.Open();
                DataBase_4.Open();
                DataBase_info.Open();
                DataBase_0.Close();
                DataBase_1.Close();
                DataBase_2.Close();
                DataBase_3.Close();
                DataBase_4.Close();
                DataBase_info.Close();
            }
            catch (SqlException)
            {
                print_message("Connection failed. DataBases states:\n" +
                    "\nDataBase #1: " + DataBase_0.State.ToString() +
                    "\nDataBase #2: " + DataBase_1.State.ToString() +
                    "\nDataBase #3: " + DataBase_2.State.ToString() +
                    "\nDataBase #4: " + DataBase_3.State.ToString() +
                    "\nDataBase #5: " + DataBase_4.State.ToString() +
                    "\nDataBase info: " + DataBase_info.State.ToString());
            }
            catch (Exception error) 
            {
                print_message("MainForm_Load: " + error.Message);
            }

            if (this.Request.QueryString.ToString().Length > 0)
            {
                var str = this.Request.QueryString.GetValues("user_id");
                //print_message(str[0].ToString());
                userid_textBox.Text = str[0];
                get_user_info();
            }
        }
Пример #6
0
 //
 //====================================================================================================
 /// <summary>
 /// Initializes cache client
 /// </summary>
 /// <remarks></remarks>
 public CacheController(CoreController core)
 {
     try {
         this.core = core;
         //
         _globalInvalidationDate = null;
         remoteCacheInitialized  = false;
         if (core.serverConfig.enableRemoteCache)
         {
             //
             // -- leave off, it causes a performance hit
             if (core.serverConfig.enableEnyimNLog)
             {
                 Enyim.Caching.LogManager.AssignFactory(new NLogFactory());
             }
             //
             // -- initialize memcached drive (Enyim)
             string cacheEndpoint = core.serverConfig.awsElastiCacheConfigurationEndpoint;
             if (!string.IsNullOrEmpty(cacheEndpoint))
             {
                 string[] cacheEndpointSplit = cacheEndpoint.Split(':');
                 int      cacheEndpointPort  = 11211;
                 if (cacheEndpointSplit.GetUpperBound(0) > 1)
                 {
                     cacheEndpointPort = GenericController.encodeInteger(cacheEndpointSplit[1]);
                 }
                 Amazon.ElastiCacheCluster.ElastiCacheClusterConfig cacheConfig = new Amazon.ElastiCacheCluster.ElastiCacheClusterConfig(cacheEndpointSplit[0], cacheEndpointPort)
                 {
                     Protocol = Enyim.Caching.Memcached.MemcachedProtocol.Binary
                 };
                 cacheClient = new Enyim.Caching.MemcachedClient(cacheConfig);
                 if (cacheClient != null)
                 {
                     remoteCacheInitialized = true;
                 }
             }
         }
     } catch (Exception ex) {
         //
         // -- client does not throw its own errors, so try to differentiate by message
         throw (new GenericException("Exception initializing remote cache, will continue with cache disabled.", ex));
     }
 }
 /// <summary>
 /// Increments the value of the specified key by the given amount. The operation is atomic and happens on the server.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
 /// <param name="delta">The amount by which the client wants to increase the item.</param>
 /// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
 /// <returns>The new value of the item or defaultValue if the key was not found.</returns>
 /// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="T:System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
 public IMutateOperationResult ExecuteIncrement(string key, ulong defaultValue, ulong delta, DateTime expiresAt)
 {
     return(this.PerformMutate(MutationMode.Increment, key, defaultValue, delta, MemcachedClient.GetExpiration(null, expiresAt)));
 }
 /// <summary>
 /// Increments the value of the specified key by the given amount. The operation is atomic and happens on the server.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
 /// <param name="delta">The amount by which the client wants to increase the item.</param>
 /// <param name="validFor">The interval after the item is invalidated in the cache.</param>
 /// <returns>The new value of the item or defaultValue if the key was not found.</returns>
 /// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="T:System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
 public IMutateOperationResult ExecuteIncrement(string key, ulong defaultValue, ulong delta, TimeSpan validFor)
 {
     return(this.PerformMutate(MutationMode.Increment, key, defaultValue, delta, MemcachedClient.GetExpiration(validFor, null)));
 }
 /// <summary>
 /// Inserts an item into the cache with a cache key to reference its location and returns its version.
 /// </summary>
 /// <param name="mode">Defines how the item is stored in the cache.</param>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
 /// <param name="cas">The cas value which must match the item's version.</param>
 /// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
 public IStoreOperationResult ExecuteCas(StoreMode mode, string key, object value, DateTime expiresAt, ulong cas)
 {
     return(this.PerformStore(mode, key, value, MemcachedClient.GetExpiration(null, expiresAt), cas));
 }
 /// <summary>
 /// Inserts an item into the cache with a cache key to reference its location and returns its version.
 /// </summary>
 /// <param name="mode">Defines how the item is stored in the cache.</param>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="validFor">The interval after the item is invalidated in the cache.</param>
 /// <param name="cas">The cas value which must match the item's version.</param>
 /// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
 public IStoreOperationResult ExecuteCas(StoreMode mode, string key, object value, TimeSpan validFor, ulong cas)
 {
     return(this.PerformStore(mode, key, value, MemcachedClient.GetExpiration(validFor, null), cas));
 }
Пример #11
0
        /// <summary>
        /// Inserts an item into the cache with a cache key to reference its location.
        /// </summary>
        /// <param name="mode">Defines how the item is stored in the cache.</param>
        /// <param name="key">The key used to reference the item.</param>
        /// <param name="value">The object to be inserted into the cache.</param>
        /// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
        /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
        public bool Store(StoreMode mode, string key, object value, DateTime expiresAt)
        {
            ulong tmp = 0;

            return(this.PerformStore(mode, key, value, MemcachedClient.GetExpiration(null, expiresAt), ref tmp));
        }
Пример #12
0
 /// <summary>
 /// Inserts an item into the cache with a cache key to reference its location.
 /// </summary>
 /// <param name="mode">Defines how the item is stored in the cache.</param>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="validFor">The interval after the item is invalidated in the cache.</param>
 /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
 public bool Store(StoreMode mode, string key, object value, TimeSpan validFor)
 {
     return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, validFor, DateTime.MinValue));
 }
Пример #13
0
 /// <summary>
 /// Inserts an item into the cache with a cache key to reference its location.
 /// </summary>
 /// <param name="mode">Defines how the item is stored in the cache.</param>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <remarks>The item does not expire unless it is removed due memory pressure.</remarks>
 /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
 public bool Store(StoreMode mode, string key, object value)
 {
     return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, MemcachedClient.Infinite, DateTime.MinValue));
 }
Пример #14
0
 /// <summary>
 /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param>
 /// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
 public bool CheckAndSet(string key, object value, ulong cas, DateTime expiresAt)
 {
     return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, TimeSpan.MinValue, expiresAt));
 }
Пример #15
0
 /// <summary>
 /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param>
 /// <remarks>The item does not expire unless it is removed due memory pressure.</remarks>
 public bool CheckAndSet(string key, object value, ulong cas)
 {
     return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, MemcachedClient.Infinite, DateTime.MinValue));
 }
Пример #16
0
 /// <summary>
 /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The data to be stored.</param>
 /// <param name="offset">A 32 bit integer that represents the index of the first byte to store.</param>
 /// <param name="length">A 32 bit integer that represents the number of bytes to store.</param>
 /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param>
 /// <remarks>The item does not expire unless it is removed due memory pressure.</remarks>
 public bool CheckAndSet(string key, byte[] value, int offset, int length, ulong cas)
 {
     return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, offset, length, MemcachedClient.Infinite, DateTime.MinValue));
 }
Пример #17
0
 /// <summary>
 /// Inserts the data before the specified item's data.
 /// </summary>
 /// <returns>true if the data was successfully stored; false otherwise.</returns>
 public bool Prepend(string key, byte[] data)
 {
     return(MemcachedClient.Store(this.pool, StoreCommand.Prepend, key, data, 0, MemcachedClient.Infinite, DateTime.MinValue));
 }
Пример #18
0
 /// <summary>
 /// Inserts a range of bytes (usually memory area or serialized data) into the cache with a cache key to reference its location.
 /// </summary>
 /// <param name="mode">Defines how the item is stored in the cache.</param>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The data to be stored.</param>
 /// <param name="offset">A 32 bit integer that represents the index of the first byte to store.</param>
 /// <param name="length">A 32 bit integer that represents the number of bytes to store.</param>
 /// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
 /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
 public bool Store(StoreMode mode, string key, byte[] value, int offset, int length, DateTime expiresAt)
 {
     return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, offset, length, TimeSpan.MinValue, expiresAt));
 }
Пример #19
0
 /// <summary>
 /// Inserts an item into the cache with a cache key to reference its location.
 /// </summary>
 /// <param name="mode">Defines how the item is stored in the cache.</param>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
 /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
 public bool Store(StoreMode mode, string key, object value, DateTime expiresAt)
 {
     return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, TimeSpan.MinValue, expiresAt));
 }
 /// <summary>
 /// Decrements the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
 /// <param name="delta">The amount by which the client wants to decrease the item.</param>
 /// <param name="validFor">The interval after the item is invalidated in the cache.</param>
 /// <param name="cas">The cas value which must match the item's version.</param>
 /// <returns>The new value of the item or defaultValue if the key was not found.</returns>
 /// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="T:System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
 public IMutateOperationResult ExecuteDecrement(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas)
 {
     return(this.CasMutate(MutationMode.Decrement, key, defaultValue, delta, MemcachedClient.GetExpiration(validFor, null), cas));
 }
Пример #21
0
 /// <summary>
 /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The data to be stored.</param>
 /// <param name="offset">A 32 bit integer that represents the index of the first byte to store.</param>
 /// <param name="length">A 32 bit integer that represents the number of bytes to store.</param>
 /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param>
 /// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
 public bool CheckAndSet(string key, byte[] value, int offset, int length, ulong cas, DateTime expiresAt)
 {
     return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, offset, length, TimeSpan.MinValue, expiresAt));
 }
 /// <summary>
 /// Decrements the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
 /// <param name="delta">The amount by which the client wants to decrease the item.</param>
 /// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
 /// <param name="cas">The cas value which must match the item's version.</param>
 /// <returns>The new value of the item or defaultValue if the key was not found.</returns>
 /// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="T:System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
 public IMutateOperationResult ExecuteDecrement(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas)
 {
     return(this.CasMutate(MutationMode.Decrement, key, defaultValue, delta, MemcachedClient.GetExpiration(null, expiresAt), cas));
 }
Пример #23
0
        /// <summary>
        /// Inserts an item into the cache with a cache key to reference its location.
        /// </summary>
        /// <param name="mode">Defines how the item is stored in the cache.</param>
        /// <param name="key">The key used to reference the item.</param>
        /// <param name="value">The object to be inserted into the cache.</param>
        /// <param name="validFor">The interval after the item is invalidated in the cache.</param>
        /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
        public bool Store(StoreMode mode, string key, object value, TimeSpan validFor)
        {
            ulong tmp = 0;

            return(this.PerformStore(mode, key, value, MemcachedClient.GetExpiration(validFor, null), ref tmp));
        }
Пример #24
0
 /// <summary>
 /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails.
 /// </summary>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param>
 /// <param name="validFor">The interval after the item is invalidated in the cache.</param>
 public bool CheckAndSet(string key, object value, ulong cas, TimeSpan validFor)
 {
     return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, validFor, DateTime.MinValue));
 }
Пример #25
0
 /// <summary>
 /// Inserts a range of bytes (usually memory area or serialized data) into the cache with a cache key to reference its location.
 /// </summary>
 /// <param name="mode">Defines how the item is stored in the cache.</param>
 /// <param name="key">The key used to reference the item.</param>
 /// <param name="value">The data to be stored.</param>
 /// <param name="offset">A 32 bit integer that represents the index of the first byte to store.</param>
 /// <param name="length">A 32 bit integer that represents the number of bytes to store.</param>
 /// <remarks>The item does not expire unless it is removed due memory pressure.</remarks>
 /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
 public bool Store(StoreMode mode, string key, byte[] value, int offset, int length)
 {
     return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, offset, length, MemcachedClient.Infinite, DateTime.MinValue));
 }