Method Get
Get(String)
Retrieves the specified item from the Cache object.
Declaration
public virtual object Get(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception in-case of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
cache.Get("MyTextBox.Value");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Get(String, TimeSpan, ref LockHandle, Boolean)
Retrieves the specified item from the Cache object if it is not already locked. Otherwise returns null (Nothing in Visual Basic). This is different from the normal Get operation where an item is returned ignoring the lock altogether.
Declaration
public virtual object Get(string key, TimeSpan lockTimeout, ref LockHandle lockHandle, bool acquireLock)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.TimeSpan | lockTimeout | The TimeSpan after which the lock is automatically released. |
LockHandle | lockHandle | An instance of |
System.Boolean | acquireLock | A flag to determine whether to acquire a lock or not. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception in case of failure.
Examples
The following example demonstrates how to retrieve the cached value and acquire a lock at the same time.
Cache theCache = NCache.InitializeCache("myreplicatedcache");
theCache.Add("cachedItemKey", new CacheItem("cachedItemValue"));
LockHandle lockHandle = new LockHandle();
object cachedItem = theCache.Get("cachedItemKey", Cache.NoLockingExpiration, ref lockHandle, true);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Get(String, DSReadOption)
Retrieves the specified item from the Cache object. If not available in cache gets from the datasource.
Declaration
public virtual object Get(string key, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
DSReadOption | dsReadOption | Options regarding reading from data source |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception in case of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
string textBoxValue = (string) cache.Get("MyTextBox.Value", DSReadOption.ReadThru);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Get(String, String, DSReadOption)
Retrieves the specified item from the Cache object.
Declaration
public virtual object Get(string key, string providerName, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | providerName | A specific name for the data source |
DSReadOption | dsReadOption | Options regarding reading from data source |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Get(String, ref CacheItemVersion)
Retrieves the specified item from the Cache object. It accepts the
Declaration
public virtual object Get(string key, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception in case of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", ref version);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Get(String, DSReadOption, ref CacheItemVersion)
Retrieves the specified item from the Cache object. If the object is read through the data source,
put it in the cache. It accepts the
Declaration
public virtual object Get(string key, DSReadOption dsReadOption, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
DSReadOption | dsReadOption | Options regarding reading from data source. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception in case of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", DSReadOption.ReadThru, ref version);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Get(String, String, DSReadOption, ref CacheItemVersion)
Retrieves the specified item from the Cache object. If the object is read through the data source,
put it in the cache. It accepts the
Declaration
public virtual object Get(string key, string providerName, DSReadOption dsReadOption, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | providerName | A specific name for the data source |
DSReadOption | dsReadOption | Options regarding reading from data source. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Get(String, String, String, DSReadOption)
Retrieves the specified item from the Cache object. If the object is read through the data source, put it against the given group and sub group.
Declaration
public virtual object Get(string key, string group, string subGroup, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | group | The name of the group which the item belongs to. |
System.String | subGroup | The name of the subGroup within a group. |
DSReadOption | dsReadOption | Options regarding reading from data source. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception in case of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", "Customer", null, DSReadOption.ReadThru);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|