NCache 4.6 - Online Documentation

Using GetBufferedStream

Buffered stream is the set of bytes used for storing the data up to the certain limit before reading or writing it to the cache. The following code shows how to use GetBufferedStream:
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching. 
    string key = "key:ncache-manual";
            byte[] writeBuffer = System.IO.File.ReadAllBytes("C:\\ncache-manual.pdf");
            int length = writeBuffer.Length;
                System.IO.Stream wstream = cache.GetCacheStream(key, StreamMode.Write).GetBufferedStream(length);
                wstream.Write(writeBuffer, 0, length / 2);//...No data is written in cache as buffer is not full
                wstream.Write(writeBuffer, length / 2, length / 2);//...Data is written in cache because buffer is full now
                //...Close the stream
            catch (StreamException ex)
                // handle exception
See Also