471,319 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 5827
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.com

"Bob Grommes" <bo*@bobgrommes.com> wrote in message
news:eS****************@TK2MSFTNGP10.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.com

"INeedADip" <IN*******@gmail.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
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<AnotherClass> 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.Encoding.Default.GetString(ms.ToArray( ));
}
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 HttpSessionState. I
thought if we were using StateServer that the objects were serialized to the
server running StateServer?
Jan 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Anders Borum | last post: by
3 posts views Thread by Jon Shemitz | last post: by
2 posts views Thread by Mr.Tickle | last post: by
23 posts views Thread by Luc Vaillant | last post: by
9 posts views Thread by sloan | last post: by
4 posts views Thread by Cedric Rogers | last post: by
13 posts views Thread by rkausch | last post: by
reply views Thread by rosydwin | last post: by

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.