473,387 Members | 1,463 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,387 software developers and data experts.

Application Data Caching

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

Jun 12 '06 #1
4 3442

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" <fr**@smartybird.com> wrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
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

Jun 12 '06 #2
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" <fr**@smartybird.com> wrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
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



Jun 12 '06 #3
You should post what you did... so others can learn and know what you
did....
if they google and find this post.
"Fred Nelson" <fr**@smartybird.com> wrote in message
news:es**************@TK2MSFTNGP04.phx.gbl...
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" <fr**@smartybird.com> wrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
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


Jun 12 '06 #4
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" <fr**@smartybird.com> wrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
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



Jun 12 '06 #5

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

Similar topics

9
by: J. Baute | last post by:
I'm caching data in the Application object to speed up certain pages on a website The main reason is that the retrieval of this data takes quite a while (a few seconds) and fetching the same data...
5
by: dave | last post by:
There seems to be plenty of discussion about caching in the Application Object, however, I cant find any info on what realistic limitations there are and how they are measured What are the...
2
by: Duncan Welch | last post by:
Good morning, I have a classic ASP app that I'm converting to .NET. In the existing app when accessing infrequntly changed data, it reads a database once a day, and saves the results in an...
3
by: Patrick | last post by:
Hi I have the following problem. When starting my asp.net application, i read a encrypted string from a file, decrypt it and want this values to be available in the complete application. they...
2
by: Oberon | last post by:
Why does this not work as it should? I expect index.aspx to show:. Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\ChatSimple\db\chatusers.mdb Instead, I get: ...
2
by: lwhitb1 | last post by:
Does anyone have any input on setting up my CAB application so that the application is thread safe, and cached appropiately? I read that this can be managed through Services, and dynamic injection....
7
by: =?Utf-8?B?Q2hyaXMgQ2Fw?= | last post by:
We are considering moving from using several seperate webservers to a web farm. I was lookingg at implementing a start server to manage state for the web farm. The problem is, how do we keep...
8
by: Andrus | last post by:
I'm creating C# WinForms client-server database application. This application reads data from PostgreSQL server using npgsql Dataadapter and DataReader classes and stores data mostly in Datasets...
6
by: goraya | last post by:
This is design level discussion about web applications. How I design application that support 1 million concurrent requests??
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.