Solved

Session state - saving an object to memory, across pages

Posted on 2004-08-31
9
683 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
  • 6
  • 2
9 Comments
 
LVL 9

Accepted Solution

by:
crescendo earned 125 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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