C# Class Whalin.Caching.Memcached.MemcachedClient

This is a C# memcachedClient for the memcached server available from http://www.danga.com/memcached/. Supports setting, adding, replacing, deleting compressed/uncompressed and serialized (can be stored as string if object is native class) objects to memcached. Now pulls SockIO objects from SockIOPool, which is a connection sockIOPool. The server failover has also been moved into the SockIOPool class. This sockIOPool needs to be initialized prior to the memcachedClient working. See javadocs from SockIOPool. (This will have to be fixed for our C# version. Most of this code is straight ported over from Java.)
显示文件 Open project: xianrendzw/LightFramework.Net

Public Methods

Method Description
Add ( string key, object value ) : bool

Adds data to the server; only the key and the value are specified.

Add ( string key, object value, System.DateTime expiry ) : bool

Adds data to the server; the key, value, and an expiration time are specified.

Add ( string key, object value, System.DateTime expiry, int hashCode ) : bool

Adds data to the server; the key, value, and an expiration time are specified.

Add ( string key, object value, int hashCode ) : bool

Adds data to the server; the key, value, and an optional hashcode are passed in.

Decrement ( string key ) : long

Decrement the value at the specified key by 1, and then return it.

Decrement ( string key, long inc ) : long

Decrement the value at the specified key by passed in value, and then return it.

Decrement ( string key, long inc, int hashCode ) : long

Decrement the value at the specified key by the specified increment, and then return it.

Delete ( string key ) : bool

Deletes an object from cache given cache key.

Delete ( string key, System.DateTime expiry ) : bool

Deletes an object from cache given cache key and expiration date.

Delete ( string key, object hashCode, System.DateTime expiry ) : bool

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.

FlushAll ( ) : bool

Invalidates the entire cache. Will return true only if succeeds in clearing all servers.

FlushAll ( ArrayList servers ) : bool

Invalidates the entire cache. Will return true only if succeeds in clearing all servers. If pass in null, then will try to flush all servers.

Get ( string key ) : object

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

Get ( string key, int hashCode ) : object

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

Get ( string key, object hashCode, bool asString ) : object

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

GetCounter ( string key ) : long

Returns value in counter at given key as long.

GetCounter ( string key, object hashCode ) : long

Returns value in counter at given key as long.

GetMultiple ( string keys ) : Hashtable

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.

GetMultiple ( string keys, int hashCodes ) : Hashtable

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.

GetMultiple ( string keys, int hashCodes, bool asString ) : Hashtable

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.

GetMultipleArray ( string keys ) : object[]

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.

GetMultipleArray ( string keys, int hashCodes ) : object[]

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.

GetMultipleArray ( string keys, int hashCodes, bool asString ) : object[]

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.

Increment ( string key ) : long

Increment the value at the specified key by 1, and then return it.

Increment ( string key, long inc ) : long

Increment the value at the specified key by passed in val.

Increment ( string key, long inc, int hashCode ) : long

Increment the value at the specified key by the specified increment, and then return it.

KeyExists ( string key ) : bool

Checks to see if key exists in cache.

MemcachedClient ( ) : System

Creates a new instance of MemcachedClient.

Replace ( string key, object value ) : bool

Updates data on the server; only the key and the value are specified.

Replace ( string key, object value, System.DateTime expiry ) : bool

Updates data on the server; the key, value, and an expiration time are specified.

Replace ( string key, object value, System.DateTime expiry, int hashCode ) : bool

Updates data on the server; the key, value, and an expiration time are specified.

Replace ( string key, object value, int hashCode ) : bool

Updates data on the server; only the key and the value and an optional hash are specified.

Set ( string key, object value ) : bool

Stores data on the server; only the key and the value are specified.

Set ( string key, object value, System.DateTime expiry ) : bool

Stores data on the server; the key, value, and an expiration time are specified.

Set ( string key, object value, System.DateTime expiry, int hashCode ) : bool

Stores data on the server; the key, value, and an expiration time are specified.

Set ( string key, object value, int hashCode ) : bool

Stores data on the server; only the key and the value are specified.

Stats ( ) : Hashtable

Retrieves stats for 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.

Stats ( ArrayList servers, string command ) : Hashtable

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.

StoreCounter ( string key, long counter ) : bool

Store a counter to memcached given a key

StoreCounter ( string key, long counter, int hashCode ) : bool

Store a counter to memcached given a key

Private Methods

Method Description
GetExpirationTime ( System.DateTime expiration ) : int

Converts a .NET date time to a UNIX timestamp

GetLocalizedString ( string key ) : string
IncrementOrDecrement ( string cmdname, string key, long inc, object hashCode ) : long

Increments/decrements the value at the specified key by inc. Note that the server uses a 32-bit unsigned integer, and checks for underflow. In the event of underflow, the result will be zero. Because Java lacks unsigned types, the value is returned as a 64-bit integer. The server will only decrement a value if it already exists; if a value is not found, -1 will be returned. TODO: C# has unsigned types. We can fix this.

Init ( ) : void

Initializes memcachedClient object to defaults. This enables compression and sets compression threshhold to 15 KB.

LoadItems ( SockIO sock, Hashtable hm, bool asString ) : void

This method loads the data from cache into a Hashtable. Pass a SockIO object which is ready to receive data and a Hashtable to store the results.

Set ( string cmdname, string key, object obj, System.DateTime expiry, object hashCode, bool asString ) : bool

Stores data to cache. If data does not already exist for this key on the server, or if the key is being deleted, the specified value will not be stored. The server will automatically delete the value when the expiration time has been reached. If compression is enabled, and the data is longer than the compression threshold the data will be stored in compressed form. As of the current release, all objects stored will use .NET serialization.

Method Details

Add() public method

Adds data to the server; only the key and the value are specified.
public Add ( string key, object value ) : bool
key string key to store data under
value object value to store
return bool

Add() public method

Adds data to the server; the key, value, and an expiration time are specified.
public Add ( string key, object value, System.DateTime expiry ) : bool
key string key to store data under
value object value to store
expiry System.DateTime when to expire the record
return bool

Add() public method

Adds data to the server; the key, value, and an expiration time are specified.
public Add ( string key, object value, System.DateTime expiry, int hashCode ) : bool
key string key to store data under
value object value to store
expiry System.DateTime when to expire the record
hashCode int if not null, then the int hashcode to use
return bool

Add() public method

Adds data to the server; the key, value, and an optional hashcode are passed in.
public Add ( string key, object value, int hashCode ) : bool
key string key to store data under
value object value to store
hashCode int if not null, then the int hashcode to use
return bool

Decrement() public method

Decrement the value at the specified key by 1, and then return it.
public Decrement ( string key ) : long
key string key where the data is stored
return long

Decrement() public method

Decrement the value at the specified key by passed in value, and then return it.
public Decrement ( string key, long inc ) : long
key string key where the data is stored
inc long how much to increment by
return long

Decrement() public method

Decrement the value at the specified key by the specified increment, and then return it.
public Decrement ( string key, long inc, int hashCode ) : long
key string key where the data is stored
inc long how much to increment by
hashCode int if not null, then the int hashcode to use
return long

Delete() public method

Deletes an object from cache given cache key.
public Delete ( string key ) : bool
key string the key to be removed
return bool

Delete() public method

Deletes an object from cache given cache key and expiration date.
public Delete ( string key, System.DateTime expiry ) : bool
key string the key to be removed
expiry System.DateTime when to expire the record.
return bool

Delete() public method

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 Delete ( string key, object hashCode, System.DateTime expiry ) : bool
key string the key to be removed
hashCode object if not null, then the int hashcode to use
expiry System.DateTime when to expire the record.
return bool

FlushAll() public method

Invalidates the entire cache. Will return true only if succeeds in clearing all servers.
public FlushAll ( ) : bool
return bool

FlushAll() public method

Invalidates the entire cache. Will return true only if succeeds in clearing all servers. If pass in null, then will try to flush all servers.
public FlushAll ( ArrayList servers ) : bool
servers System.Collections.ArrayList optional array of host(s) to flush (host:port)
return bool

Get() public method

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 Get ( string key ) : object
key string key where data is stored
return object

Get() public method

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 Get ( string key, int hashCode ) : object
key string key where data is stored
hashCode int if not null, then the int hashcode to use
return object

Get() public method

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 Get ( string key, object hashCode, bool asString ) : object
key string key where data is stored
hashCode object if not null, then the int hashcode to use
asString bool if true, then return string val
return object

GetCounter() public method

Returns value in counter at given key as long.
public GetCounter ( string key ) : long
key string cache ket
return long

GetCounter() public method

Returns value in counter at given key as long.
public GetCounter ( string key, object hashCode ) : long
key string cache ket
hashCode object if not null, then the int hashcode to use
return long

GetMultiple() public method

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.
public GetMultiple ( string keys ) : Hashtable
keys string string array of keys to retrieve
return System.Collections.Hashtable

GetMultiple() public method

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.
public GetMultiple ( string keys, int hashCodes ) : Hashtable
keys string string array of keys to retrieve
hashCodes int hashCodes if not null, then the int array of hashCodes
return System.Collections.Hashtable

GetMultiple() public method

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.
public GetMultiple ( string keys, int hashCodes, bool asString ) : Hashtable
keys string string array of keys to retrieve
hashCodes int hashCodes if not null, then the int array of hashCodes
asString bool if true then retrieve using string val
return System.Collections.Hashtable

GetMultipleArray() public method

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.
public GetMultipleArray ( string keys ) : object[]
keys string string array of keys to retrieve
return object[]

GetMultipleArray() public method

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.
public GetMultipleArray ( string keys, int hashCodes ) : object[]
keys string string array of keys to retrieve
hashCodes int if not null, then the int array of hashCodes
return object[]

GetMultipleArray() public method

Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(string), since it is more efficient.
public GetMultipleArray ( string keys, int hashCodes, bool asString ) : object[]
keys string string array of keys to retrieve
hashCodes int if not null, then the int array of hashCodes
asString bool asString if true, retrieve string vals
return object[]

Increment() public method

Increment the value at the specified key by 1, and then return it.
public Increment ( string key ) : long
key string key where the data is stored
return long

Increment() public method

Increment the value at the specified key by passed in val.
public Increment ( string key, long inc ) : long
key string key where the data is stored
inc long how much to increment by
return long

Increment() public method

Increment the value at the specified key by the specified increment, and then return it.
public Increment ( string key, long inc, int hashCode ) : long
key string key where the data is stored
inc long how much to increment by
hashCode int if not null, then the int hashcode to use
return long

KeyExists() public method

Checks to see if key exists in cache.
public KeyExists ( string key ) : bool
key string the key to look for
return bool

MemcachedClient() public method

Creates a new instance of MemcachedClient.
public MemcachedClient ( ) : System
return System

Replace() public method

Updates data on the server; only the key and the value are specified.
public Replace ( string key, object value ) : bool
key string key to store data under
value object value to store
return bool

Replace() public method

Updates data on the server; the key, value, and an expiration time are specified.
public Replace ( string key, object value, System.DateTime expiry ) : bool
key string key to store data under
value object value to store
expiry System.DateTime when to expire the record
return bool

Replace() public method

Updates data on the server; the key, value, and an expiration time are specified.
public Replace ( string key, object value, System.DateTime expiry, int hashCode ) : bool
key string key to store data under
value object value to store
expiry System.DateTime when to expire the record
hashCode int if not null, then the int hashcode to use
return bool

Replace() public method

Updates data on the server; only the key and the value and an optional hash are specified.
public Replace ( string key, object value, int hashCode ) : bool
key string key to store data under
value object value to store
hashCode int if not null, then the int hashcode to use
return bool

Set() public method

Stores data on the server; only the key and the value are specified.
public Set ( string key, object value ) : bool
key string key to store data under
value object value to store
return bool

Set() public method

Stores data on the server; the key, value, and an expiration time are specified.
public Set ( string key, object value, System.DateTime expiry ) : bool
key string key to store data under
value object value to store
expiry System.DateTime when to expire the record
return bool

Set() public method

Stores data on the server; the key, value, and an expiration time are specified.
public Set ( string key, object value, System.DateTime expiry, int hashCode ) : bool
key string key to store data under
value object value to store
expiry System.DateTime when to expire the record
hashCode int if not null, then the int hashcode to use
return bool

Set() public method

Stores data on the server; only the key and the value are specified.
public Set ( string key, object value, int hashCode ) : bool
key string key to store data under
value object value to store
hashCode int if not null, then the int hashcode to use
return bool

Stats() public method

Retrieves stats for 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 Stats ( ) : Hashtable
return System.Collections.Hashtable

Stats() public method

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 Stats ( ArrayList servers, string command ) : Hashtable
servers System.Collections.ArrayList string array of servers to retrieve stats from, or all if this is null
command string 命令行参数,该参数为DiscuzNT修改版
return System.Collections.Hashtable

StoreCounter() public method

Store a counter to memcached given a key
public StoreCounter ( string key, long counter ) : bool
key string cache key
counter long number to store
return bool

StoreCounter() public method

Store a counter to memcached given a key
public StoreCounter ( string key, long counter, int hashCode ) : bool
key string cache key
counter long number to store
hashCode int if not null, then the int hashcode to use
return bool