C# Класс 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.)
Показать файл Открыть проект

Открытые методы

Метод Описание
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

Приватные методы

Метод Описание
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.

Описание методов

Add() публичный Метод

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
Результат bool

Add() публичный Метод

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
Результат bool

Add() публичный Метод

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
Результат bool

Add() публичный Метод

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
Результат bool

Decrement() публичный Метод

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
Результат long

Decrement() публичный Метод

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
Результат long

Decrement() публичный Метод

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
Результат long

Delete() публичный Метод

Deletes an object from cache given cache key.
public Delete ( string key ) : bool
key string the key to be removed
Результат bool

Delete() публичный Метод

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.
Результат bool

Delete() публичный Метод

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.
Результат bool

FlushAll() публичный Метод

Invalidates the entire cache. Will return true only if succeeds in clearing all servers.
public FlushAll ( ) : bool
Результат bool

FlushAll() публичный Метод

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)
Результат bool

Get() публичный Метод

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
Результат object

Get() публичный Метод

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
Результат object

Get() публичный Метод

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
Результат object

GetCounter() публичный Метод

Returns value in counter at given key as long.
public GetCounter ( string key ) : long
key string cache ket
Результат long

GetCounter() публичный Метод

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
Результат long

GetMultiple() публичный Метод

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
Результат System.Collections.Hashtable

GetMultiple() публичный Метод

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
Результат System.Collections.Hashtable

GetMultiple() публичный Метод

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
Результат System.Collections.Hashtable

GetMultipleArray() публичный Метод

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
Результат object[]

GetMultipleArray() публичный Метод

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
Результат object[]

GetMultipleArray() публичный Метод

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
Результат object[]

Increment() публичный Метод

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
Результат long

Increment() публичный Метод

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
Результат long

Increment() публичный Метод

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
Результат long

KeyExists() публичный Метод

Checks to see if key exists in cache.
public KeyExists ( string key ) : bool
key string the key to look for
Результат bool

MemcachedClient() публичный Метод

Creates a new instance of MemcachedClient.
public MemcachedClient ( ) : System
Результат System

Replace() публичный Метод

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
Результат bool

Replace() публичный Метод

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
Результат bool

Replace() публичный Метод

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
Результат bool

Replace() публичный Метод

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
Результат bool

Set() публичный Метод

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
Результат bool

Set() публичный Метод

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
Результат bool

Set() публичный Метод

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
Результат bool

Set() публичный Метод

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
Результат bool

Stats() публичный Метод

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
Результат System.Collections.Hashtable

Stats() публичный Метод

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修改版
Результат System.Collections.Hashtable

StoreCounter() публичный Метод

Store a counter to memcached given a key
public StoreCounter ( string key, long counter ) : bool
key string cache key
counter long number to store
Результат bool

StoreCounter() публичный Метод

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
Результат bool