Class StreamCache

Namespace: redb.Route.Core
Assembly: redb.Route.dll

A stream that holds content in memory up to a threshold and spools the rest to a temporary file, then reads it back
from the start as often as needed — Camel's StreamCache. The .StreamCaching() step wraps a forward-only
body in one; a connector uses one to spool what it must not hand to the route before it is complete and checked
(a decrypted attachment whose tag and signature are verified only at the end).

Two phases. While writing (, ,
) it cannot be read; rewinds it and turns it
read-only and seekable. The temporary file is opened with : disposing the
cache — the exchange does, when it owns the body — removes it.

public sealed class StreamCache : Stream, IDisposable, IAsyncDisposable

Inheritance

Object→MarshalByRefObject→Stream→StreamCache

Implements

Properties

CanRead

When overridden in a derived class, gets a value indicating whether the current stream supports reading.

public override bool CanRead { get; }

CanSeek

When overridden in a derived class, gets a value indicating whether the current stream supports seeking.

public override bool CanSeek { get; }

CanWrite

When overridden in a derived class, gets a value indicating whether the current stream supports writing.

public override bool CanWrite { get; }

IsSpooled

Whether the content went past the threshold and lives in a temporary file.

public bool IsSpooled { get; }

Length

When overridden in a derived class, gets the length in bytes of the stream.

public override long Length { get; }

Position

When overridden in a derived class, gets or sets the position within the current stream.

public override long Position { get; set; }

Methods

CacheFromSourceAsync(Stream, CancellationToken)

Reads all of source into the cache and completes writing. The source is not disposed: its

public Task CacheFromSourceAsync(Stream source, CancellationToken ct = default)

CompleteWriting()

Ends the writing phase: the cache rewinds and becomes read-only and seekable.

public void CompleteWriting()

Dispose(bool)

Releases the unmanaged resources used by the and optionally releases the managed resources.

protected override void Dispose(bool disposing)

DisposeAsync()

Asynchronously releases the unmanaged resources used by the .

public override ValueTask DisposeAsync()

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.

public override void Flush()

OpenReader()

Opens an independent read-only view of the completed cache, positioned at the start: it has a position of its own,

public Stream OpenReader()

Read(byte[], int, int)

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of byt...

public override int Read(byte[] buffer, int offset, int count)

Read(Span<byte>)

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of byt...

public override int Read(Span<byte> buffer)

ReadAsync(byte[], int, int, CancellationToken)

Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors ca...

public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken ct)

ReadAsync(Memory<byte>, CancellationToken)

Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors ca...

public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken ct = default)

Seek(long, SeekOrigin)

When overridden in a derived class, sets the position within the current stream.

public override long Seek(long offset, SeekOrigin origin)

SetLength(long)

When overridden in a derived class, sets the length of the current stream.

public override void SetLength(long value)

Write(byte[], int, int)

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the numbe...

public override void Write(byte[] buffer, int offset, int count)

Write(ReadOnlySpan<byte>)

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the numbe...

public override void Write(ReadOnlySpan<byte> buffer)

WriteAsync(byte[], int, int, CancellationToken)

Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and ...

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken ct)

WriteAsync(ReadOnlyMemory<byte>, CancellationToken)

Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and ...

public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken ct = default)

Constructors

StreamCache(StreamCacheOptions?)

Creates a cache with the threshold and temporary directory of options (defaults when null).