Method GetCacheItem
GetCacheItem(String)
Get the cache item stored in cache.
Declaration
[TargetMethod(1)]
public virtual CacheItem GetCacheItem(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key used to reference the desired object |
Returns
Type | Description |
---|---|
CacheItem | CacheItem |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase 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");
CacheItem item = cache.GetCacheItem(key);
GetCacheItem(String, String, String)
Get the cache item stored in cache.
Declaration
[TargetMethod(2)]
[Obsolete("Use GetCacheItem(string key, string group, string subGroup, DSReadOption dsReadOption)")]
public virtual CacheItem GetCacheItem(string key, string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key used to reference the desired object |
System.String | group | The group of the cache item. Items with the same group are logically grouped together. |
System.String | subGroup | The sub-group within a group. |
Returns
Type | Description |
---|---|
CacheItem | CacheItem |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase 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");
CacheItem item = cache.GetCacheItem(key, "group-name", "subgroup-name");
GetCacheItem(String, TimeSpan, ref LockHandle, Boolean)
Get the cache item stored in cache.
Declaration
[TargetMethod(3)]
public virtual CacheItem GetCacheItem(string key, TimeSpan lockTimeout, ref LockHandle lockHandle, bool acquireLock)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key used to reference the desired object |
System.TimeSpan | lockTimeout | The TimeSpan after which the lock is automatically released. |
LockHandle | lockHandle | An instance of LockHandle to hold the lock information. |
System.Boolean | acquireLock | A flag to determine whether to acquire a lock or not. |
Returns
Type | Description |
---|---|
CacheItem | 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 incase 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");
LockHandle lockHandle = new LockHandle();
CacheItem item = cache.GetCacheItem("cachedItemKey",TimeSpan.FromSeconds(30) , ref lockHandle, true);
GetCacheItem(String, DSReadOption)
Retrieves the specified item from the Cache object.
Declaration
[TargetMethod(4)]
public virtual CacheItem GetCacheItem(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 |
---|---|
CacheItem | 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 incase 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 |
|
GetCacheItem(String, String, DSReadOption)
Retrieves the specified item from the Cache object.
Declaration
[TargetMethod(5)]
public virtual CacheItem GetCacheItem(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 |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
GetCacheItem(String, ref CacheItemVersion)
Retrieves the specified item from the Cache object. It accepts the CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(6)]
public virtual CacheItem GetCacheItem(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 |
---|---|
CacheItem | 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 incase 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 |
|
GetCacheItem(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 CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(5)]
public virtual CacheItem GetCacheItem(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 |
---|---|
CacheItem | 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 incase 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 |
|
GetCacheItem(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 CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(7)]
public virtual CacheItem GetCacheItem(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 |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
GetCacheItem(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
[TargetMethod(8)]
public virtual CacheItem GetCacheItem(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 |
---|---|
CacheItem | 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 incase 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 |
|