views:

233

answers:

1

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?

+1  A: 

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

Ramesh Vel
Files are rather big and I'd like to partially cache them.
bh213