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

name 'cache' is not declared?

I'm accessing an XML file several times on a page, and, as such, want to
cache it.

I'm setting it up as such:

if cache("xmlFile") is nothing then...
load file
cache file
else
read it
end if

This works fine in my codebehind, but I'm trying to move this out into a
standalone class so I can call it from various usercontrols. When I do this,
I get an error of "name 'cache' is not declared?'

Is this a namespace issue? I don't declare a more specific namespace in my
codebehind page that uses it (other than System.Web.UI.UserControl), so I'm
confused as to what namespace is missing.

-Darrel
Nov 19 '05 #1
9 1374
Try including the System.Web.Caching namespace in your standalone code.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"darrel" <no*****@hotmail.com> wrote in message
news:eZ*************@TK2MSFTNGP10.phx.gbl...
I'm accessing an XML file several times on a page, and, as such, want to
cache it.

I'm setting it up as such:

if cache("xmlFile") is nothing then...
load file
cache file
else
read it
end if

This works fine in my codebehind, but I'm trying to move this out into a
standalone class so I can call it from various usercontrols. When I do this, I get an error of "name 'cache' is not declared?'

Is this a namespace issue? I don't declare a more specific namespace in my
codebehind page that uses it (other than System.Web.UI.UserControl), so I'm confused as to what namespace is missing.

-Darrel

Nov 19 '05 #2
You will need to access Cache through the HttpContent.Current property.

if System.Web.HttpContext.Current.Cache( "xmlFile" ) is nothing then
...

HTH,

bill
"darrel" <no*****@hotmail.com> wrote in message
news:eZ*************@TK2MSFTNGP10.phx.gbl...
I'm accessing an XML file several times on a page, and, as such, want to
cache it.

I'm setting it up as such:

if cache("xmlFile") is nothing then...
load file
cache file
else
read it
end if

This works fine in my codebehind, but I'm trying to move this out into a
standalone class so I can call it from various usercontrols. When I do this, I get an error of "name 'cache' is not declared?'

Is this a namespace issue? I don't declare a more specific namespace in my
codebehind page that uses it (other than System.Web.UI.UserControl), so I'm confused as to what namespace is missing.

-Darrel

Nov 19 '05 #3
> Try including the System.Web.Caching namespace in your standalone code.

I tried that as such:

if System.Web.Caching.cache("footerText") Is Nothing Then

but get this error:

'cache' is a type in 'caching' and can not be used as an expression.

-Darrel
Nov 19 '05 #4
VB.NET :
myValue = Cache("mykey")
If Not (myValue Is Nothing) Then
DisplayData(myValue)
End If

C# :
myValue = Cache("mykey");
if(myValue != null ) {
DisplayData(myValue);
}
You could add a dependency with :

VB.NET :
Cache.Insert("MyData", Source, _
New CacheDependency(Server.MapPath("your.xml")))

C# :
Cache.Insert("MyData", Source,
new CacheDependency(Server.MapPath("your.xml")));

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"darrel" <no*****@hotmail.com> wrote in message
news:eZ*************@TK2MSFTNGP10.phx.gbl...
I'm accessing an XML file several times on a page, and, as such, want to
cache it.

I'm setting it up as such:

if cache("xmlFile") is nothing then...
load file
cache file
else
read it
end if

This works fine in my codebehind, but I'm trying to move this out into a
standalone class so I can call it from various usercontrols. When I do
this,
I get an error of "name 'cache' is not declared?'

Is this a namespace issue? I don't declare a more specific namespace in my
codebehind page that uses it (other than System.Web.UI.UserControl), so
I'm
confused as to what namespace is missing.

-Darrel



Nov 19 '05 #5
> You will need to access Cache through the HttpContent.Current property.

if System.Web.HttpContext.Current.Cache( "xmlFile" ) is nothing then


Aha! That's it! Thanks!

Now, why do I need to be so explicit when doing this in a standalone class
vs. doing it in on a codebehind page? Also, is there a trick to 'reverse
lookup' the namespace a particular object exists in? I noticed on MSDN, that
there are a variety of cache objects, so I wasn't really finding the
specific namespage I was looking for.

-Darrel
Nov 19 '05 #6
When you are coding this in a codebehind page, the page itself has a Cache
property. When the page is being created by the framework, Response,
Request, Session, etc are all pulled from HttpContext.Current and assigned
to the page.

The page (codebehind) just does it automatically for you.

I am not sure what you are asking about a "reverse lookup". Clarify if you
would like an answer.

bill

"darrel" <no*****@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
You will need to access Cache through the HttpContent.Current property.

if System.Web.HttpContext.Current.Cache( "xmlFile" ) is nothing then
Aha! That's it! Thanks!

Now, why do I need to be so explicit when doing this in a standalone class
vs. doing it in on a codebehind page? Also, is there a trick to 'reverse
lookup' the namespace a particular object exists in? I noticed on MSDN,

that there are a variety of cache objects, so I wasn't really finding the
specific namespage I was looking for.

-Darrel

Nov 19 '05 #7
> When you are coding this in a codebehind page, the page itself has a Cache
property. When the page is being created by the framework, Response,
Request, Session, etc are all pulled from HttpContext.Current and assigned
to the page.
Well, that makes sense! Thanks for explaining that.
I am not sure what you are asking about a "reverse lookup". Clarify if you would like an answer.


Well, often I want to use a specific command/object etc. Lots of tutorials
on the web use small snippets of code, and don't always explicitely show you
what namespace the commands/funcctions/objects belong to.

In VS.net, you can start typing a namespace and it will show you it's
children automatically. I was wondering how one goes about doing the
reverse...picking a object and figuring out what it's parent namespace is.
Is there a way to search MSDN for that information? Sometimes, MSDN
information is arranged by namespace, so I can just follow the hierarchy up,
but, for example, in this case with Cache, I was completely lost as to how
to figure out what namespace I needed.

-Darrel
Nov 19 '05 #8
No, there is no "reverse lookup". You will just need to become familiar
with the .NET namespaces and the classes within. Visual Studio Whidbey
(.net 2.0) will have this feature. When you declare a type and the
namespace isn't included, there will be an option to declare the namespace
at the top, but for now, there is nothing.

bill
"darrel" <no*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
When you are coding this in a codebehind page, the page itself has a Cache property. When the page is being created by the framework, Response,
Request, Session, etc are all pulled from HttpContext.Current and assigned to the page.
Well, that makes sense! Thanks for explaining that.
I am not sure what you are asking about a "reverse lookup". Clarify if

you
would like an answer.


Well, often I want to use a specific command/object etc. Lots of tutorials
on the web use small snippets of code, and don't always explicitely show

you what namespace the commands/funcctions/objects belong to.

In VS.net, you can start typing a namespace and it will show you it's
children automatically. I was wondering how one goes about doing the
reverse...picking a object and figuring out what it's parent namespace is.
Is there a way to search MSDN for that information? Sometimes, MSDN
information is arranged by namespace, so I can just follow the hierarchy up, but, for example, in this case with Cache, I was completely lost as to how
to figure out what namespace I needed.

-Darrel

Nov 19 '05 #9
> No, there is no "reverse lookup". You will just need to become familiar
with the .NET namespaces and the classes within. Visual Studio Whidbey
(.net 2.0) will have this feature.


Damn. Yet another reason for me to get more anxious waiting for that update
;o)

Thanks, bill!

-Darrel
Nov 19 '05 #10

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

Similar topics

4
by: Dan Jacobson | last post by:
Using <A name="x_y-z"></A>, I even get nervous about the _ and -. w3-recs/RECS/html4/struct/links.html seems to say all of ascii is cool and beyond. Anyway, just what is the safe range for...
4
by: NWx | last post by:
Hi, I' trying to implement a callback method when a cache object expires I want to do this to automatically logout user after a timeout (for demo purposes) My thought is, when user logon,...
0
by: NWx | last post by:
Hi, I discovered a strange (?!?!) issue related objects saved to cache. Let's explain my situation. I have a webform for user registration. Users enter username, password and other info...
2
by: TJS | last post by:
I get this erro from a vb class file. line 86. Line 84: Dim dt As New DataTable() Line 85: da.Fill(dt) Line 86: Cache.Add("ScrollExampleCustomerData", dt,...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
9
by: Michael M. | last post by:
Hi all, I would like to know how to access the NT/2000/XP/2003 Name cache; what I mean by this is: Open a Command Prompt and.., C:\> C:\>IPCONFIG /DISPLAYDNS
4
by: andrew | last post by:
Hi, I have routinely added anchors to pages using both name and id: <a name="example" id="example"></a> under the possibly mistaken assumption that at some stage "name" might be deprecated...
1
by: MSwanston | last post by:
Hi I need some help with saving retreiving data from the cache, and how best to structure my code. FYI am working in VS2005/under .NET2 Framework. Ok, we have a series of reports that get run via...
2
by: helveticus | last post by:
How can I assign expiration dates for external js scripts? For instance, I would like to update the expiration date of a js script by one hour after the last fetch. Does this make sense? I have...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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: 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...
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...
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...

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.