• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

Stream Processing in Cache

Note

This feature is only available in NCache Enterprise Edition.

Storing large amounts of data (media files or large PDF documents) directly into the cache using cache API is inefficient. You will have to first load the entire file into the application memory and then put it into the cache as a single object. It eventually results in higher memory consumption at the client end. NCache provides Streaming API, which enables you to read or write large binary data into the cache in the form of smaller chunks. Moreover, it allows you to simultaneously open multiple parallel streams into the cache.

When is it Useful

Suppose you have a high-traffic application that contains large media files that can be viewed by the users, while you keep frequently viewed media files in your cache for fast access. Adding and fetching a large media file in cache can be costly if you add or fetch it at once, even asynchronously. Meanwhile, such applications require high performance and real-time response. In this regard, streams can effectively reduce time and memory costs by allowing you to write and read large objects in the form of chunks.

Warning

In NCache, serialization/de-serialization, compression/decompression or encryption/decryption is not applied to the streams.

Stream Buffers

Streams are directly fetched from or inserted to specified storage (here in cache) in general. You can also add a buffer in between storage and stream. Then the stream is added to that buffer first. Once the buffer is full, it is written to the cache or loaded where needed. For using buffer in streaming, you only have to specify the size of the buffer. Buffering can provide a significant performance boost by reducing the response time.

Note

The default size of a stream buffer is 4K.

Stream Modes

NCache provides different streaming modes that enable read/write access while retrieving/updating data using streams in cache. Any of these modes must be specified based on your desired operation.

Stream Read
In Read mode, read operations can be performed simultaneously on a stream by multiple clients but no write operation is allowed in this mode. This mode can be specified when you want to ensure data consistency in presence of multiple applications.

Stream Read without Lock
In ReadWithoutLock mode, write operations can be performed in parallel to read operations because read operations do not acquire any lock to stop writing. You can read data by specifying ReadWithoutLock mode when there is need to process the data concurrently.

Stream Write
In Write mode, only a single write operation can be performed on a stream. No read operation is allowed in this mode. Even threads having write locks cannot read that stream.

Note

NCache Stream does not support Seek operation.

Important

You should properly close an opened stream to release the lock as other threads may be waiting for that stream to be available. If a stream is not closed, any other threads trying to acquire locks will receive an exception.

In This Section

Add/Update Cache Data with Streams
Explains how to add data to a stream or update the added data.

Retrieve Cache Data from Streams
Explains how you retrieve a data from a stream.

Back to top Copyright © 2017 Alachisoft