0

I have a class object which contains some data members and methods. I want to store this object for later use in the application.

Let me know which approach like session, cache etc is good in terms of performance.

Person per1 = new Person();

Here i want store the per1 object for later use in the application

Raptor
  • 53,206
  • 45
  • 230
  • 366
user1931944
  • 175
  • 2
  • 2
  • 9
  • Have a look http://stackoverflow.com/questions/11490864/difference-between-cache-and-session-in-real-time-for-asp-net http://stackoverflow.com/questions/14653065/what-is-difference-between-session-cache-and-profile-in-asp-net – Revan Mar 26 '14 at 09:31
  • Application collects personal details of the users and stores them. In order to retrieve, each time calling database ...i want to keep them in some storage type like session or cache or other approach. Want to which gives best performance in times. Hope it is clear – user1931944 Mar 26 '14 at 09:33
  • You need serialization, then save to file / DB. – Raptor Mar 26 '14 at 09:41
  • Say If i want to access a method of Person class then i must deserialize the object first and get the required data, I think it takes some time. Correct me if I am wrong – user1931944 Mar 26 '14 at 09:46

2 Answers2

2

You use cache typically when you want to improve site performance: reduce database calls, accessing files on filesystem, calling external services, etc.

Session is used to store user-specific information that could be accessible from all web pages and will not be needed on next time user logs in.

Refer

what is difference between session, cache and profile in asp.net

Difference between cache and session in real time for Asp.Net

Community
  • 1
  • 1
Revan
  • 1,104
  • 12
  • 27
0

you can mark the object as serializable and store it and then deserialize it to load it again.

Serialization(you have to save it in any directory of your computer)

  XmlSerializer serializer = new XmlSerializer(per1.GetType());
   StreamWriter writer = new StreamWriter(@"D:\Temporary\myfile.xml");
   serializer.Serialize(writer.BaseStream, per1);

Desirialization(load it from that directory)

XmlSerializer serializer = new XmlSerializer(per1.GetType());
StreamReader reader = new StreamReader(@"D:\Temporary\myfile.xml");
object deserialized = serializer.Deserialize(reader.BaseStream);
city = (Person)deserialized;
Safwan
  • 171
  • 1
  • 17