简体   繁体   中英

Caching stream in c#

I have a bunch of files that are being read by another bunch of threads. Some parts of files get read multiple times using multiple file opens. I'd like to have a sort of caching file stream.

If part of the file was read before, all subsequent reads would come from cache, otherwise file part would be read and content added to cache.

Files do not change, so there is no need to invalidate cache.

Is anyone aware of such class being available somewhere or similar mechanism that would help with such problem?

If the file size is small you can use shared MemoryStream object to cache the file streams. But am not sure about caching the part of a file and identifying the part of a file from cache.

You can cache the whole file in a memorystream and you can use it whenever needed. And you can identify this using the filename as a key. For this you have to maintain a list or dictionary kind of structure to store filename (key) - binarystream(value) pairs.

these below links discussed the same topics. have a look

hope this helps

Cheers

Ramesh Vel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM