#if MYSQL_6_9 // Copyright © 2004, 2013, Oracle and/or its affiliates. All rights reserved. // // MySQL Connector/NET is licensed under the terms of the GPLv2 // , like most // MySQL Connectors. There are special exceptions to the terms and // conditions of the GPLv2 as it is applied to this software, see the // FLOSS License Exception // . // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published // by the Free Software Foundation; version 2 of the License. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA namespace Externals.MySql.Data.MySqlClient.Memcached { using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Net; using Externals.MySql.Data.Common; using Externals.MySql.Data.MySqlClient.Properties; /// /// An interface of the client memcached protocol. This class is abstract for /// implementation of the Memcached client interface see for the /// text protocol version and for the binary protocol version. /// internal abstract class Client { /// /// The port used by the connection. /// protected uint port; /// /// The server DNS or IP address used by the connection. /// protected string server; /// /// The network stream used by the connecition. /// protected Stream stream; /// /// Factory method for creating instances of that implement a connection with the requested features. /// The connection object returned must be explicitely opened see method . /// /// The Memcached server DNS or IP address. /// The port for the Memcached server /// A set of flags indicating characterestics requested. /// An instance of a client connection ready to be used. public static Client GetInstance(string server, uint port, MemcachedFlags flags) { if ((flags | MemcachedFlags.TextProtocol) != 0) { return new TextClient(server, port); } else if ( ( flags | MemcachedFlags.BinaryProtocol ) != 0 ) { return new BinaryClient(server, port); } return null; } /// /// Opens the client connection. /// public virtual void Open() { this.stream = StreamCreator.GetStream(server, port, null, 10, new DBVersion(), 60); } /// /// Closes the client connection. /// public virtual void Close() { stream.Dispose(); } protected Client(string server, uint port) { this.server = server; this.port = port; } /// /// Adds a new key/value pair with the given TimeSpan expiration. /// /// The key for identifying the entry. /// The data to associate with the key. /// The interval of timespan, use TimeSpan.Zero for no expiration. public abstract void Add(string key, object data, TimeSpan expiration); /// /// Appens the data to the existing data for the associated key. /// /// The key for identifying the entry. /// The data to append with the data associated with the key. public abstract void Append(string key, object data); /// /// Executes the Check-and-set Memcached operation. /// /// The key for identifying the entry. /// The data to use in the CAS. /// The interval of timespan, use TimeSpan.Zero for no expiration. /// The CAS unique value to use. /// public abstract void Cas(string key, object data, TimeSpan expiration, ulong casUnique); /// /// Decrements the value associated with a key by the given amount. /// /// The key associated with the value to decrement. /// The amount to decrement the value. public abstract void Decrement(string key, int amount); /// /// Removes they pair key/value given the specified key. /// /// public abstract void Delete(string key); /// /// Removes all entries from the storage, effectively invalidating the whole cache. /// /// The interval after which the cache will be cleaned. Can be TimeSpan.Zero for immediately. public abstract void FlushAll(TimeSpan delay); /// /// Get the key/value pair associated with a given key. /// /// The key for which to returm the key/value. /// The key/value associated with the key or a MemcachedException if it does not exists. public abstract KeyValuePair Get(string key); /// /// Increments the value associated with a key by the given amount. /// /// The key associated with the value to increment. /// The amount to increment the value. public abstract void Increment(string key, int amount); /// /// Prepends the data to the existing data for the associated key. /// /// The key for identifying the entry. /// The data to append with the data associated with the key. public abstract void Prepend(string key, object data); /// /// Replaces the value associated with the given key with another value. /// /// The key for identifying the entry. /// The data to replace the value associated with the key. /// The interval of timespan, use TimeSpan.Zero for no expiration. public abstract void Replace(string key, object data, TimeSpan expiration); /// /// Set the value of a given key. /// /// The key for identifying the entry. /// The data to associate with the given key. /// The interval of timespan, use TimeSpan.Zero for no expiration. public abstract void Set(string key, object data, TimeSpan expiration); } /// /// A set of flags for requesting new instances of connections /// [Flags] internal enum MemcachedFlags : ushort { /// /// Requests a connection implememting the text protocol. /// TextProtocol = 0x1, /// /// Requests a connection implementing the binary protocol. /// BinaryProtocol = 0x2, /// /// Requests a TCP connection. Currently UDP is not supported. /// Tcp = 0x4 } } #endif