I'm working on an application that should store some PDF for later printing. I have an implementation that is checking what size the PDF is and according to the size I choose between Memory or File Streams (<2GB = MemStream and >2GB = FileStream).
When I am using the FileStream the performance varies and I just noticed that this is caused by the Windows Memory Cache. Basically everything i am using to write/read to/from a FileStream will get into this cache and after saving 6 PDFs I get really low performance (30 seconds compared to 60s+)
I declare my FileStream in the following way:
FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, 524288, FileOptions.WriteThrough))
I just added the WriteThrough option but it does not seem to fix the issue. Is there a possibility that after I save the file to disk and close/dispose the FileStream I get the cache memory cleared?
Thank you in advance!
__________edit___________
adding code snippets.
loadStream = new FileStream(@"C:\temp\FileStream_test.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.None, 524288);
request.InputStream.CopyTo(loadStream);
loadStream.Flush();
loadStream.Position = 0;
and 2nd one
using (var mimePDL = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, 524288, FileOptions.WriteThrough))
{
mimeParts[contentID].Content.DecodeTo(mimePDL);
mimePDL.Position = 0;
mimePDL.Flush(true);
mimePDL.Close();
mimePDL.Dispose();
}
And for the first one I dispose of it this way
loadStream.Close();
loadStream.Dispose();
File.Delete(((FileStream)loadStream).Name);