473,383 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Can I store a C# Class Instance to the Server Cache?

Of course, I can store a C# class instance to the Server Cache
(this.Context.Cache). I've tried it. My question is, will this destroy the
scalability of my application?

My background is VB6. With VB6 we learned very early on that you do *NOT*
store VB6 class instances on the server. That is because a VB6 class can
only be accessed on the thread on which it is created (thread affinity).
This is just incompatible with stateless web architecture since with this
architecture every client request will likely be served by different ASP
pages executing on different threads. However, if VB6 classes are stored to
the Session object, then the ASP execution is going to block until the
thread on which the class instance was created becomes available.

Is this limitation still inherent with .NET classes, or are .NET class
instances 'safe' in this regard?

(Of course, the solution would be to serialize to XML and store the XML
string, but if I can safely store the class reference, why bother?)

Thanks for your advice!

- Joseph Geretz -
Feb 14 '07 #1
5 2146
"Joseph Geretz" <jg*****@nospam.comwrote in message
news:eO****************@TK2MSFTNGP02.phx.gbl...
Of course, I can store a C# class instance to the Server Cache
(this.Context.Cache). I've tried it. My question is, will this destroy the
scalability of my application?

My background is VB6. With VB6 we learned very early on that you do *NOT*
store VB6 class instances on the server. That is because a VB6 class can
only be accessed on the thread on which it is created (thread affinity).
This is not a problem with .NET. You have to make sure the class is
serializable.

John
Feb 14 '07 #2
Hi John,

Thanks for your response. I'm not sure what you mean by serializable. Do you
mean that I need to serialize this explicitly into the Cache, or that the
Framework will take care of the serialization for me if the class is
serializable?

Here is that class which I am caching.

internal class SessionCache
{
public string SID;
public string UID;
public string PWD;
public DataTable Profile;
}

I know this is 'working' since I'm able to retrieve this from the cache on
successive Web Method requests. Is this actually being serialized into the
cache for me 'under the hood'? Does it need to be? Do I need to do anything
explicitly to serialize this into the cache?

Thanks for your advice!

- Joseph Geretz -

"John Saunders" <john.saunders at trizetto.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
"Joseph Geretz" <jg*****@nospam.comwrote in message
news:eO****************@TK2MSFTNGP02.phx.gbl...
>Of course, I can store a C# class instance to the Server Cache
(this.Context.Cache). I've tried it. My question is, will this destroy
the scalability of my application?

My background is VB6. With VB6 we learned very early on that you do *NOT*
store VB6 class instances on the server. That is because a VB6 class can
only be accessed on the thread on which it is created (thread affinity).

This is not a problem with .NET. You have to make sure the class is
serializable.

John


Feb 14 '07 #3
"Joseph Geretz" <jg*****@nospam.comwrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
Hi John,

Thanks for your response. I'm not sure what you mean by serializable. Do
you mean that I need to serialize this explicitly into the Cache, or that
the Framework will take care of the serialization for me if the class is
serializable?

Here is that class which I am caching.

internal class SessionCache
{
public string SID;
public string UID;
public string PWD;
public DataTable Profile;
}

I know this is 'working' since I'm able to retrieve this from the cache on
successive Web Method requests. Is this actually being serialized into the
cache for me 'under the hood'? Does it need to be? Do I need to do
anything explicitly to serialize this into the cache?
Joseph, I'm sorry, I wasn't thinking clearly. I was thinking about
ViewState, which _does_ require instances to be serializable. Clearly, the
ASP.NET Cache object doesn't need anything more than your class provides.

John
Feb 14 '07 #4
Thanks John,
Clearly, the ASP.NET Cache object doesn't need anything more than your
class provides
I know this works, but will I run into any threading problems? In other
words, let's say the user logs in with an instance of the ASMX page
executing on thread 345. The SessionCache class instance will be created on
thread 345 and a reference to that class instance will be stuffed into the
Server Cache. Let's say the next transaction for this user's session is
served up by an ASMX page executing on thread 987. Will access to the
SessionCache class instance involve a thread context switch from 987 to 345?
This is the sort of trap which looks like it's working initially, but as
usage scales up, this sort of problem will start to manifest itself in a big
way. (Forgive me for stressing the point, but a lot VB6 developers were
burned badly by saving class instances on the Server and I want to make sure
that .NET class instances aren't succeptible to the same type of thread
affinity problems.)

Thanks!

- Joseph Geretz -

"John Saunders" <john.saunders at trizetto.comwrote in message
news:OO**************@TK2MSFTNGP03.phx.gbl...
"Joseph Geretz" <jg*****@nospam.comwrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
>Hi John,

Thanks for your response. I'm not sure what you mean by serializable. Do
you mean that I need to serialize this explicitly into the Cache, or that
the Framework will take care of the serialization for me if the class is
serializable?

Here is that class which I am caching.

internal class SessionCache
{
public string SID;
public string UID;
public string PWD;
public DataTable Profile;
}

I know this is 'working' since I'm able to retrieve this from the cache
on successive Web Method requests. Is this actually being serialized into
the cache for me 'under the hood'? Does it need to be? Do I need to do
anything explicitly to serialize this into the cache?

Joseph, I'm sorry, I wasn't thinking clearly. I was thinking about
ViewState, which _does_ require instances to be serializable. Clearly, the
ASP.NET Cache object doesn't need anything more than your class provides.

John


Feb 15 '07 #5
"Joseph Geretz" <jg*****@nospam.comwrote in message
news:eJ**************@TK2MSFTNGP03.phx.gbl...
Thanks John,
>Clearly, the ASP.NET Cache object doesn't need anything more than your
class provides

I know this works, but will I run into any threading problems?
Joseph, all of that COM-era thread affinity stuff is gone in .NET.

John
Feb 15 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: NWx | last post by:
Hi, Is Cache appropriate to store persistent variables used across the application? What I want is to store UserID for currently logged user, SessionID (my own SessionID, which keep track of...
0
by: Mark | last post by:
I'm trying to port the asp.net unleashed sample store from SQLServer to Access. I have it all do, execpt when I try and add something to the cart I geet this error: Exception Details:...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
7
by: Göran Tänzer | last post by:
Hi, i've written a class which does some calculations for my web application. These informatinos are different for each page request - the current user is not important. i have about 10 aspx...
2
by: Steve | last post by:
I am developing an asp.net 2.0 application and have come across the dilemma of how to store constant values, which change infrequently. The website will have tens of thousands of visitors every...
3
by: Hans Merkl | last post by:
Hi, I am helping to build a web app that's pretty much a wrapper around a web service. The question now is how to store the handle of the web service object between requests. My client is using...
18
by: siddharthkhare | last post by:
Hi All, what is the diference between these two cache control header. no-cache and no-store. I have read the w3.org explanation. So lets say I am using only no-cache ....my understanding is...
4
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code...
3
by: | last post by:
Hello all, I'd like some advices from more experienced python users. I want to have a class in my python application that does not allow multiple instance with same "name". I want to have a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.