?
Solved

Session state - saving an object to memory, across pages

Posted on 2004-08-31
9
Medium Priority
?
686 Views
Last Modified: 2010-05-18
Hi,

I am creating a framework for an e-commerce site, which is to be used and extended for our customers.

Now I would like people to be able to add things to their shopping carts, but then I would like these carts stored in memory, rather than on the SQL Server, for performance mainly.

If I have a dataset with 2 tables in it, how can I make this persist across the whole site, and how would I go about accessing a specific dataset?

Thanks
0
Comment
Question by:betocarranza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 9

Accepted Solution

by:
crescendo earned 375 total points
ID: 11942336
if your dataset is "ds", just do

   Session("myDataset") = ds

That will store the dataset in a session variable. Just do the opposite to use it on another page.

   Dim ds As Dataset = Session("myDataset")
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942373
By the way, it's not particularly efficient if the dataset is large. You will have a dataset in a dataset variable, plus a copy in a session variable, thereby using twice as much memory as needed. Each user using the site has their own set of session variables, so on a busy site the dataset copies could eat up a lot of memory.
0
 
LVL 2

Expert Comment

by:netjkus
ID: 11942381
Basically, if you are on a webFarm , you cannot use Inproc. You are forced to use SQLServer or Stateserver. However storing anything other than the basic types like Objects etc will be too slow in SQLServer or Stateserver. Try to modify the logic so that you dont need the entire table in memory. If you are storing the cart for this session alone, you might have other options. But if you are stioring the cart till the user clears it, you have less choice.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:betocarranza
ID: 11942426
There are 2 kinds of users

1) Registered users, if they add something to a cart it stays there until they delete it or empty it (this case I would probably use SQL Server)

2) Unregister users, create a temporary cartID for them (a guid) and store this cart in memory. If they register, the cart will be saved, if not, they can still check it out or whatever, so it should remain in memory on the server.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942436
It's pretty common to store carts in cookies or SQL tables. Performance isn't generally an issue, because people only add items to their cart occasionally. Certainly not often enough! Most of their time is sent browsing and thinking. I use SQL tables personally, but cookies are just as valid. One benefit is that you can save carts across browser restarts, but you can't do that with session variables.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942463
I would use the same method whether the user is registered or not, to make code maintenance easier. Just save something to say that they need to register on checkout.
0
 
LVL 2

Author Comment

by:betocarranza
ID: 11942549
Okay, I will have a look at the cookies method, might be a lot easier than session variables!

How is the actual cart stored in a cookie though?
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942910
Any way you can think of!

Try a string with ItemID and quantity values separated by a semicolon. Separate each item with CrLf. Its' easy enough to parse out. Save a separate string in the cookie as the shopper's ID or temporary ID.
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11942931
To set values in cookies use something like this:


                Response.Cookies("CartContents").Value = sCart

                Response.Cookies("CartContents").Expires = DateTime.Now.AddMonths(1)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question