Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Session state - saving an object to memory, across pages

Posted on 2004-08-31
9
Medium Priority
?
687 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
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…

604 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