Is there a way to force windows to cache a file in RAM

Most of the time the bottleneck isn't so much getting the file from disk to RAM but rather from RAM to network. Unless the system is very bogged down in activity or low on RAM, Windows should handle file caching fairly intelligently.

You might want to do some testing and see if there really is a bottleneck with your system that would see marked improvement by keeping certain files in memory versus swapped to disk when Windows thinks it should be saved to disk. I'm betting you'll save very little time as the bottleneck would most likely be the network, and by the time the file is queued up to go to the network the drive is already filling buffers in memory as it pulls the file off the drive.

That said, the only really reliable way to have data files held in memory that I know of is to create a RAM disk and copy the files there, assuming they are static. Otherwise you have a power outage and they're gone.

Otherwise you might want to invest in lots of RAM and high speed disk drives. Maybe even a mirrored RAID configuration, as that has a high read (slower write) performance. I'd let Windows and the memory manager do it's thing, and focus on minimizing access time with better subsystems (fast disk, RAID, lots of memory, high speed and high quality NIC) rather than tweaking it to the point that debugging or troubleshooting could become more of a pain down the road.


You can try supercache or other alternate cache solutions, or you may want to consider using a SSD with high speed read access - That will saturate almost any network connection pretty easily.

The only other option I don't think matches your needs but I'll mention it:

If you are WRITING the file in your application you can try creating with:

FILE_ATTRIBUTE_TEMPORARY and FILE_FLAG_DELETE_ON_CLOSE

This tells Windows to try to keep files in RAM instead of on disk - I don't think this will match your needs though but you can read more at http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx#caching_behavior

Steve Radich - http://www.BitShop.com/blogs.aspx

Tags:

Windows

Cache