Closing a Stream
The stream should be closed after being used in any mode in order to release the lock.
To utilize the API, include the following namespace in your application:
Alachisoft.NCache.Web.Caching.
string key = "key:ncache-guide";
try
{
CacheStream cacheStream = cache.GetCacheStream(key, StreamMode.Read);
int dataSize = Convert.ToInt32(cacheStream.Length);
byte[] dataToRead = newbyte[dataSize];
cacheStream.Read(dataToRead, 0, dataSize);
// your logic here
cacheStream.Close();
}
catch (StreamException e)
{
// handle exception
}
Reading or writing a stream that was previously in use throws exception i.e.
StreamAlreadyLockedException
, if it was not closed properly.