Solved

Session state - saving an object to memory, across pages

Posted on 2004-08-31
9
681 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now