PC Review


Reply
Thread Tools Rate Thread

Application Data Caching

 
 
Fred Nelson
Guest
Posts: n/a
 
      12th Jun 2006
Hi:

This is probably a newby question however I can't figure it out!

I'm trying to use application data caching in a web application. I have
read an article on 4 guys from rolla that shows the following syntax:

Write:

Cache["key"] = value;

Read:

value = Cache["key"] - or - value = Cache.Get["key"]

I can save the value (or I think I can) with the "write" statement / I
am unable to get the values back with the "read":


I receive the compile message:

Cannot apply indexing with [] to an expression of type 'method group'

Does anyone know how to make this work?

Also: I would very much like to be able to read and update cache values
in a class library. I have added the reference System.Web.Caching
however this doesn't work - is there a way to do this?

Thanks very much!

Fred

 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      12th Jun 2006

when you pull items from the cache, they are "object"'s ... you may have to
cast it to the appropriate type.

object o = null;
if (null!=Cache["key"])
{
o = Cache["key"];
}
DataSet ds = o as DataSet;

if(null!=ds)
{
Console.Writeline(ds.GetXml());
}

That of course .. is if you put a dataset into the cache.

There is a "smarter" way to do this:


see
http://spaces.msn.com/sholliday/ 10/24/2005 entry

it would be trivial to change this from a Session to an Application holder.





"Fred Nelson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi:
>
> This is probably a newby question however I can't figure it out!
>
> I'm trying to use application data caching in a web application. I have
> read an article on 4 guys from rolla that shows the following syntax:
>
> Write:
>
> Cache["key"] = value;
>
> Read:
>
> value = Cache["key"] - or - value = Cache.Get["key"]
>
> I can save the value (or I think I can) with the "write" statement / I
> am unable to get the values back with the "read":
>
>
> I receive the compile message:
>
> Cannot apply indexing with [] to an expression of type 'method group'
>
> Does anyone know how to make this work?
>
> Also: I would very much like to be able to read and update cache values
> in a class library. I have added the reference System.Web.Caching
> however this doesn't work - is there a way to do this?
>
> Thanks very much!
>
> Fred
>



 
Reply With Quote
 
Fred Nelson
Guest
Posts: n/a
 
      12th Jun 2006
Hi Sloan:

Thank you very much for the post - I have it working now!

Fred


sloan wrote:

>
> when you pull items from the cache, they are "object"'s ... you may have to
> cast it to the appropriate type.
>
> object o = null;
> if (null!=Cache["key"])
> {
> o = Cache["key"];
> }
> DataSet ds = o as DataSet;
>
> if(null!=ds)
> {
> Console.Writeline(ds.GetXml());
> }
>
> That of course .. is if you put a dataset into the cache.
>
> There is a "smarter" way to do this:
>
>
> see
> http://spaces.msn.com/sholliday/ 10/24/2005 entry
>
> it would be trivial to change this from a Session to an Application holder.
>
>
>
>
>
> "Fred Nelson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi:
> >
> > This is probably a newby question however I can't figure it out!
> >
> > I'm trying to use application data caching in a web application. I have
> > read an article on 4 guys from rolla that shows the following syntax:
> >
> > Write:
> >
> > Cache["key"] = value;
> >
> > Read:
> >
> > value = Cache["key"] - or - value = Cache.Get["key"]
> >
> > I can save the value (or I think I can) with the "write" statement / I
> > am unable to get the values back with the "read":
> >
> >
> > I receive the compile message:
> >
> > Cannot apply indexing with [] to an expression of type 'method group'
> >
> > Does anyone know how to make this work?
> >
> > Also: I would very much like to be able to read and update cache values
> > in a class library. I have added the reference System.Web.Caching
> > however this doesn't work - is there a way to do this?
> >
> > Thanks very much!
> >
> > Fred
> >

>
>


 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      12th Jun 2006
You should post what you did... so others can learn and know what you
did....
if they google and find this post.


"Fred Nelson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Sloan:
>
> Thank you very much for the post - I have it working now!
>
> Fred
>
>
> sloan wrote:
>
> >
> > when you pull items from the cache, they are "object"'s ... you may have

to
> > cast it to the appropriate type.
> >
> > object o = null;
> > if (null!=Cache["key"])
> > {
> > o = Cache["key"];
> > }
> > DataSet ds = o as DataSet;
> >
> > if(null!=ds)
> > {
> > Console.Writeline(ds.GetXml());
> > }
> >
> > That of course .. is if you put a dataset into the cache.
> >
> > There is a "smarter" way to do this:
> >
> >
> > see
> > http://spaces.msn.com/sholliday/ 10/24/2005 entry
> >
> > it would be trivial to change this from a Session to an Application

holder.
> >
> >
> >
> >
> >
> > "Fred Nelson" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi:
> > >
> > > This is probably a newby question however I can't figure it out!
> > >
> > > I'm trying to use application data caching in a web application. I

have
> > > read an article on 4 guys from rolla that shows the following syntax:
> > >
> > > Write:
> > >
> > > Cache["key"] = value;
> > >
> > > Read:
> > >
> > > value = Cache["key"] - or - value = Cache.Get["key"]
> > >
> > > I can save the value (or I think I can) with the "write" statement / I
> > > am unable to get the values back with the "read":
> > >
> > >
> > > I receive the compile message:
> > >
> > > Cannot apply indexing with [] to an expression of type 'method group'
> > >
> > > Does anyone know how to make this work?
> > >
> > > Also: I would very much like to be able to read and update cache

values
> > > in a class library. I have added the reference System.Web.Caching
> > > however this doesn't work - is there a way to do this?
> > >
> > > Thanks very much!
> > >
> > > Fred
> > >

> >
> >

>



 
Reply With Quote
 
Fred Nelson
Guest
Posts: n/a
 
      12th Jun 2006
Hi Again:

Sloan suggested that I post my code - a good idea - so here it is:

The working code - this handels a string:

Write:

Cache["key1"] = "This is a string saved in application cache";


Read:

object ostring = null;
if (null != Cache["key1"])
{ ostring = Cache["key1"]; };

// if not null (otherwise load blank):

string mystring = ostring as string;


Fred


Fred Nelson wrote:

> Hi Sloan:
>
> Thank you very much for the post - I have it working now!
>
> Fred
>
>
> sloan wrote:
>
> >
> > when you pull items from the cache, they are "object"'s ... you may have to
> > cast it to the appropriate type.
> >
> > object o = null;
> > if (null!=Cache["key"])
> > {
> > o = Cache["key"];
> > }
> > DataSet ds = o as DataSet;
> >
> > if(null!=ds)
> > {
> > Console.Writeline(ds.GetXml());
> > }
> >
> > That of course .. is if you put a dataset into the cache.
> >
> > There is a "smarter" way to do this:
> >
> >
> > see
> > http://spaces.msn.com/sholliday/ 10/24/2005 entry
> >
> > it would be trivial to change this from a Session to an Application holder.
> >
> >
> >
> >
> >
> > "Fred Nelson" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi:
> > >
> > > This is probably a newby question however I can't figure it out!
> > >
> > > I'm trying to use application data caching in a web application. I have
> > > read an article on 4 guys from rolla that shows the following syntax:
> > >
> > > Write:
> > >
> > > Cache["key"] = value;
> > >
> > > Read:
> > >
> > > value = Cache["key"] - or - value = Cache.Get["key"]
> > >
> > > I can save the value (or I think I can) with the "write" statement / I
> > > am unable to get the values back with the "read":
> > >
> > >
> > > I receive the compile message:
> > >
> > > Cannot apply indexing with [] to an expression of type 'method group'
> > >
> > > Does anyone know how to make this work?
> > >
> > > Also: I would very much like to be able to read and update cache values
> > > in a class library. I have added the reference System.Web.Caching
> > > however this doesn't work - is there a way to do this?
> > >
> > > Thanks very much!
> > >
> > > Fred
> > >

> >
> >

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question about caching using the caching application block EL 2 =?Utf-8?B?YWhtX2VidXNpbmVzc190cg==?= Microsoft Dot NET Framework 0 19th Sep 2005 06:51 PM
Caching data in Windows application John Microsoft Dot NET Framework 2 15th Jul 2005 08:11 PM
Caching data in Windows application amrendrakr@gmail.com Microsoft C# .NET 1 13th Jul 2005 01:39 PM
Caching data in Windows application John Microsoft Dot NET Framework 0 13th Jul 2005 09:46 AM
Application Keeps Caching all Form Data Darren Smith Microsoft Dot NET Framework 0 10th May 2004 05:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:46 AM.