c# - Storing MemoryStream in Cache -


I have come across this code in one of my code, in which a static function to return a memorystream from a file , Which is then stored in the cache. Now there is a constructor in the same class that allows MemoryStream to be stored and used later in a private variable. So it looks like this:

  Private MemoryStream Memorystream; Public domain (memorystream ms) {memoryStream = ms; } Public stable memorystream filematometer (string filepath) {memorystream memorystream = new memorystream (); ReadFileTememoryStream (file path, memorystream); Return memorystream; }  

Usage:

  context.cache.indert ("test", countrylookup.fileToMemory (Configuration Settings. AppSettings ["test"]), New Cash Dependency (SomeFileName));  

and then:

  country area cl = new country content ((memory memorandum) cache. Get ("test")));  

So I was wondering who smashstream should be settled and when? Ideally CountryLookup should implement IDisposable.

Should I also take care of this?

It's a bit ugly - in particular, memorystream is disorganized, because in it The concept of "current situation" is.

Why not just store a byte array? You can easily create several memorystream which wrap the same byte array when you need it, and you do not have to worry about the state's potential.

Memorystream Typically is not required to settle, but I personally take them out of habit if you take asynchronous action on them or use them in remoting , Then I believe that the settlement does make a difference at that point byte arrays are only simple :)


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -