Click or drag to resize
Memcache Class
Supports setting, adding, replacing, deleting compressed/uncompressed and serialized (can be stored as string if object is native class) objects to memcached.
Inheritance Hierarchy
SystemObject
  AdfMemcache

Namespace: Adf
Assembly: Adf (in Adf.dll) Version: 4.1.5549.27750
Syntax
public class Memcache : ICache, IPoolInstance, 
	IDisposable

The Memcache type exposes the following members.

Constructors
  NameDescription
Public methodMemcache(String, Int32)
初始化新实例
Public methodMemcache(String, Int32, Encoding)
初始化新实例
Top
Methods
  NameDescription
Public methodAdd(String, Object)
Adds data to the server; only the key and the value are specified.
Public methodAdd(String, Object, DateTime)
Adds data to the server; the key, value, and an expiration time are specified.
Public methodClearEndOfLine
reads up to end of line and returns nothing
Public methodDecrement(String)
Decrement the value at the specified key by 1, and then return it.
Public methodDecrement(String, Int64)
Decrement the value at the specified key by passed in value, and then return it.
Public methodDelete(String)
Deletes an object from cache given cache key.
Public methodDelete(String, DateTime)
Deletes an object from cache given cache key, a delete time, and an optional hashcode. The item is immediately made non retrievable.
Keep in mind: add(string, object) and replace(string, object) will fail when used with the same key will fail, until the server reaches the specified time. However, set(string, object) will succeed and the new value will not be deleted.
Public methodDispose
资源释放
Public methodEquals
确定指定的 Object 是否等于当前的 Object
(Inherited from Object.)
Protected methodFinalize
允许 Object 在“垃圾回收”回收 Object 之前尝试释放资源并执行其他清理操作。
(Inherited from Object.)
Public methodFlush
flushes output stream
Public methodFlushAll
Invalidates the entire cache. Will return true only if succeeds in clearing all servers.
Public methodGet(String)
Retrieve a key from the server, using a specific hash. If the data was compressed or serialized when compressed, it will automatically be decompressed or serialized, as appropriate. (Inclusive or) Non-serialized data will be returned as a string, so explicit conversion to numeric types will be necessary, if desired
Public methodGet(String, Type)
Retrieve a key from the server, using a specific hash. If the data was compressed or serialized when compressed, it will automatically be decompressed or serialized, as appropriate. (Inclusive or) Non-serialized data will be returned as a string, so explicit conversion to numeric types will be necessary, if desired
Public methodGetT(String)
Retrieve a key from the server, using a specific hash. If the data was compressed or serialized when compressed, it will automatically be decompressed or serialized, as appropriate. (Inclusive or) Non-serialized data will be returned as a string, so explicit conversion to numeric types will be necessary, if desired
Public methodGetCounter
Returns value in counter at given key as long.
Public methodGetHashCode
用作特定类型的哈希函数。
(Inherited from Object.)
Public methodGetType
获取当前实例的 Type
(Inherited from Object.)
Public methodIncrement(String)
Increment the value at the specified key by 1, and then return it.
Public methodIncrement(String, Int64)
Increment the value at the specified key by passed in val.
Protected methodMemberwiseClone
创建当前 Object 的浅表副本。
(Inherited from Object.)
Public methodRead
reads length bytes into the passed in byte array from stream
Public methodReadLine
reads a line intentionally not using the deprecated readLine method from DataInputStream
Public methodReplace(String, Object)
Updates data on the server; only the key and the value are specified.
Public methodReplace(String, Object, DateTime)
Updates data on the server; the key, value, and an expiration time are specified.
Public methodSet(String, Object)
Stores data on the server; only the key and the value are specified.
Public methodSet(String, Object, DateTime)
Stores data on the server; the key, value, and an expiration time are specified.
Public methodSet(String, Object, Int32)
设置数据
Public methodStats
Retrieves stats for passed in servers (or all servers). Returns a map keyed on the servername. The value is another map which contains stats with stat name as key and value as value.
Public methodStoreCounter(String, Int64)
Store a counter to memcached given a key
Public methodStoreCounter(String, Int64, Int32)
Store a counter to memcached given a key
Public methodToString
返回表示当前 ObjectString
(Inherited from Object.)
Public methodWrite(Byte)
writes a byte array to the output stream
Public methodWrite(Byte, Int32, Int32)
writes a byte array to the output stream
Top
Properties
  NameDescription
Public propertyBinarySerializable
获取或设置二进制序列化器,默认 JsonBinarySerializable, 可通过在appsetting中配置 MemcacheBinarySerializable 来指定其它实例
Public propertyCompressionThreshold
Sets the required length for data to be considered for compression. If the length of the data to be stored is not equal or larger than this value, it will not be compressed. This defaults to 15 KB.
Public propertyEnableCompression
Enable storing compressed data, provided it meets the threshold requirements. If enabled, data will be stored in compressed form if it is longer than the threshold length set with setCompressThreshold(int) The default is that compression is enabled. Even if compression is disabled, compressed data will be automatically decompressed.
Public propertyEncoding
Sets default string encoding when storing primitives as strings. Default is UTF-8.
Public propertyHost
主机
Public propertyIsConnected
Gets whether or not the socket is connected. Returns true if it is.
Public propertyPoolAbandon
获取或设置是否放弃此实例
Public propertyPort
端口
Public propertySendTimeout
发送超时
Top
Examples
//***To create cache client object and set params:*** Memcache mc = new Memcache(); // compression is enabled by default mc.setCompressEnable(true); // set compression threshhold to 4 KB (default: 15 KB) mc.setCompressThreshold(4096); //***To store an object:*** Memcache mc = new Memcache(); string key = "cacheKey1"; object value = SomeClass.getObject(); mc.set(key, value); //***To store an object using a custom server hashCode:*** //The set method shown here will always set the object in the cache. //The add and replace methods do the same, but with a slight difference. // add -- will store the object only if the server does not have an entry for this key // replace -- will store the object only if the server already has an entry for this key Memcache mc = new Memcache(); string key = "cacheKey1"; object value = SomeClass.getObject(); int hash = 45; mc.set(key, value, hash); //***To delete a cache entry:*** Memcache mc = new Memcache(); string key = "cacheKey1"; mc.delete(key); //***To delete a cache entry using a custom hash code:*** Memcache mc = new Memcache(); string key = "cacheKey1"; int hash = 45; mc.delete(key, hashCode); //***To store a counter and then increment or decrement that counter:*** Memcache mc = new Memcache(); string key = "counterKey"; mc.storeCounter(key, 100); Console.WriteLine("counter after adding 1: " mc.incr(key)); Console.WriteLine("counter after adding 5: " mc.incr(key, 5)); Console.WriteLine("counter after subtracting 4: " mc.decr(key, 4)); Console.WriteLine("counter after subtracting 1: " mc.decr(key)); //***To store a counter and then increment or decrement that counter with custom hash:*** Memcache mc = new Memcache(); string key = "counterKey"; int hash = 45; mc.storeCounter(key, 100, hash); Console.WriteLine("counter after adding 1: " mc.incr(key, 1, hash)); Console.WriteLine("counter after adding 5: " mc.incr(key, 5, hash)); Console.WriteLine("counter after subtracting 4: " mc.decr(key, 4, hash)); Console.WriteLine("counter after subtracting 1: " mc.decr(key, 1, hash)); //***To retrieve an object from the cache:*** Memcache mc = new Memcache(); string key = "key"; object value = mc.get(key); //***To retrieve an object from the cache with custom hash:*** Memcache mc = new Memcache(); string key = "key"; int hash = 45; object value = mc.get(key, hash); //***To retrieve an multiple objects from the cache*** Memcache mc = new Memcache(); string[] keys = { "key", "key1", "key2" }; object value = mc.getMulti(keys); //***To retrieve an multiple objects from the cache with custom hashing*** Memcache mc = new Memcache(); string[] keys = { "key", "key1", "key2" }; int[] hashes = { 45, 32, 44 }; object value = mc.getMulti(keys, hashes); //***To flush all items in server(s)*** Memcache mc = new Memcache(); mc.FlushAll(); //***To get stats from server(s)*** Memcache mc = new Memcache(); Hashtable stats = mc.stats();
See Also

Reference