473,582 Members | 3,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generics in Cache

Can I put a generic List<MyObject> in cache?
I read that generics can't be serialized..

Can I cache them? Can I return them from Web Services?
Jan 13 '06 #1
4 5929
Putting something in the cache doesn't involve serializing it. The
cache (and the session and application objects) are just collections
that you're adding to.

Perhaps you're thinking of ViewState, which requires that objects added
to it be serializable because their references aren't added to
ViewState, a serialized copy is added. This allows the object contents
to be stored in the viewstate.

I don't know where you read that generics can't be serialized. Check
this out:

www.devx.com/dotnet/Article/30158/0/page/2

--Bob

INeedADip wrote:
Can I put a generic List<MyObject> in cache?
I read that generics can't be serialized..

Can I cache them? Can I return them from Web Services?

Jan 13 '06 #2
That's not necessarily true.

If the backing for the session state is ASP State server or sql server,
then yes, serialization is required by the types that you are going to store
there.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Bob Grommes" <bo*@bobgrommes .com> wrote in message
news:eS******** ********@TK2MSF TNGP10.phx.gbl. ..
Putting something in the cache doesn't involve serializing it. The cache
(and the session and application objects) are just collections that you're
adding to.

Perhaps you're thinking of ViewState, which requires that objects added to
it be serializable because their references aren't added to ViewState, a
serialized copy is added. This allows the object contents to be stored in
the viewstate.

I don't know where you read that generics can't be serialized. Check this
out:

www.devx.com/dotnet/Article/30158/0/page/2

--Bob

INeedADip wrote:
Can I put a generic List<MyObject> in cache?
I read that generics can't be serialized..

Can I cache them? Can I return them from Web Services?

Jan 13 '06 #3
INeedADip,

Generics can be serialized. However, the requirements for them being
serialized are that the type has to be marked as Serializable (and all the
fields have to be serializable as well).

If your type parameters are stored as fields in your object, then you
have to make sure those types are serializable as well.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"INeedADip" <IN*******@gmai l.com> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Can I put a generic List<MyObject> in cache?
I read that generics can't be serialized..

Can I cache them? Can I return them from Web Services?

Jan 13 '06 #4
I have a class with List<AnotherCla ss> as a property.

Then I try to serialize my entire class with:

string ret = string.Empty;
using (MemoryStream ms = new MemoryStream())
{
SoapFormatter sf = new SoapFormatter() ;
sf.Serialize(ms , this);
ret = System.Text.Enc oding.Default.G etString(ms.ToA rray());
}
return ret;

And it blows up every time saying it can't serialize generics....
"Serializer does not support serializing Generic Types"
When I said cache I was actually referring to the HttpSessionStat e. I
thought if we were using StateServer that the objects were serialized to the
server running StateServer?
Jan 13 '06 #5

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

Similar topics

13
1770
by: Anders Borum | last post by:
Hello! Now that generics are introduces with the next version of C#, I was wondering what kind of performance gains we're going to see, when switching from e.g. the general hashtable to a hashtable that supports (or implements) generics? I haven't tried generics hands-on, but I would assume that once you don't have to do casting anymore,...
3
1406
by: Jon Shemitz | last post by:
Is there a way in 2.0 to say that a generic can not be applied to a value type? public class Unique<T> where T: new() { private static T cache = default(T); public static T Instance { get {
2
3094
by: Mr.Tickle | last post by:
So whats the deal here regarding Generics in the 2004 release and templates currently in C++?
23
2530
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics vs C++ templates. Does anyone knows a workaround to do this ? Thx : public class C<T> { private T myValue;
12
2729
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as it defines the language more completely. Great to use.
1
1618
by: WT | last post by:
Hello, I was using hastable to store collection of objects of the same class MyClass. I start replacing this hastable by a Dictionary<string,MyClass>....but I was storing this hastable in cache an accessing it from another component in an Provider. This component was developped in a separate assembly and loaded dynamically. There was no...
9
5966
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal Experience Only, Please. ...
4
2802
by: Cedric Rogers | last post by:
I wasn't sure if I could do this. I believe I am stretching the capability of what generics can do for me but here goes. I have a generic delegate defined as public delegate bool RuleDelegate<T>(T item); In my class my goal is to use a generic list collection to contain my generic delegates. This will allow me to pass this List to...
13
3808
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The...
0
7886
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8159
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6569
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1413
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.