Class CacheStream
CacheStream is derived from System.IO.Stream. It is designed to put/fetch BLOB using standard Stream interface.
Inheritance
Namespace:
Assembly: Alachisoft.NCache.Web.dll
Syntax
public class CacheStream : Stream, IDisposable
CanRead
Gets a value indicating whether the current stream supports reading.
Declaration
public override bool CanRead { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
Remarks
Returns 'True' if stream is opened with either StreamMode.Read or StreamMode.ReadWithoutLock.
CanSeek
Gets a value indicating whether the current stream supports seeking.
Declaration
public override bool CanSeek { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
Remarks
Alwasy returns 'False' because CacheStream does not support seek operation.
CanWrite
Gets a value indicating whether the current stream supports writing.
Declaration
public override bool CanWrite { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
Remarks
Returns 'True' if stream is opened with StreamMode.Write.
Length
Gets the length of the stream.
Declaration
public override long Length { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
Overrides
Exceptions
Type | Condition |
---|---|
System.ObjectDisposedException | Stream is closed. |
StreamAlreadyLockedException | Stream is already locked. |
StreamInvalidLockException | Lock acquired by current stream has become invalid. |
StreamNotFoundException | Stream is not found in the cache. |
Position
Gets/Sets the position within current stream.
Declaration
public override long Position { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Stream does not support seeking. |
Close()
Closes the current stream and releases any resources associated with the current stream.
Declaration
public override void Close()
Overrides
Remarks
A call to Close is required if stream is opened with StreamMode.Read or StreamMode.Write to release locks.
Exceptions
Type | Condition |
---|---|
StreamAlreadyLockedException | Stream is already locked. |
StreamInvalidLockException | Lock acquired by current stream has become invalid. |
StreamNotFoundException | Stream is not found in the cache. |
Flush()
When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
Declaration
public override void Flush()
Overrides
Remarks
CacheStream does not buffer the data. Each read/write operations is performed on the cache.
GetBufferedStream()
Gets System.IO.BufferedStream of given buffer size.
Declaration
public Stream GetBufferedStream()
Returns
Type | Description |
---|---|
System.IO.Stream | An instance of System.IO.BufferedStream with buffer size of 4Kb. |
Remarks
CacheStream does not buffer the data. Each read/write operation performed on the stream is propagated to cache. However this can cause performance issues if small chunks of data are being read/written from/to stream. System.IO.BufferedStream supports buffering of data. This method returns an instance of System.IO.BufferedStream which encapsulates CacheStream.
GetBufferedStream(Int32)
Gets System.IO.BufferedStream of given buffer size.
Declaration
public Stream GetBufferedStream(int bufferSize)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bufferSize | Buffer size in bytes. |
Returns
Type | Description |
---|---|
System.IO.Stream | An instance of System.IO.BufferedStream. |
Remarks
CacheStream does not buffer the data. Each read/write operation performed on the stream is propagated to cache. However this can cause performance issues if small chunks of data are being read/written from/to stream. System.IO.BufferedStream supports buffering of data. This method returns an instance of System.IO.BufferedStream which encapsulates CacheStream.
Read(Byte[], Int32, Int32)
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source. |
System.Int32 | offset | The zero-based byte offset in buffer at which to begin storing the data read from the current stream. |
System.Int32 | count | The maximum number of bytes to be read from the current stream. |
Returns
Type | Description |
---|---|
System.Int32 | The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached. |
Overrides
Remarks
This method is not thread-safe
Exceptions
Type | Condition |
---|---|
StreamAlreadyLockedException | Stream is already locked. |
StreamInvalidLockException | Lock acquired by current stream has become invalid. |
StreamNotFoundException | Stream is not found in the cache. |
Seek(Int64, SeekOrigin)
Sets the position within the current stream.
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | offset | A byte offset relative to the origin parameter. |
System.IO.SeekOrigin | origin | A value of type SeekOrigin indicating the reference point used to obtain the new position. |
Returns
Type | Description |
---|---|
System.Int64 |
Overrides
Remarks
CacheStream does not support seeking.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Stream does not support seeking. |
SetLength(Int64)
Sets the length of the stream.
Declaration
public override void SetLength(long value)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value | The desired length of the current stream in bytes. |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Stream does not support both writing and seeking |
Write(Byte[], Int32, Int32)
Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | An array of bytes. This method copies count bytes from buffer to the current stream. |
System.Int32 | offset | The zero-based byte offset in buffer at which to begin copying bytes to the current stream. |
System.Int32 | count | The number of bytes to be written to the current stream. |
Overrides
Remarks
This method is not thread-safe
Exceptions
Type | Condition |
---|---|
StreamAlreadyLockedException | Stream is already locked. |
StreamInvalidLockException | Lock acquired by current stream has become invalid. |
StreamNotFoundException | Stream is not found in the cache. |