.NETGURU
Cache unavailable
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcache' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Ryan Garner
I have created a class and added it to my ASP.Net project.

I am trying to use ASP.Net cacheing from this class, so I inherited the System.Web.UI.Page, so that I could use it.

It builds okay, but when I go access the page from the browser I get a "Cache not available" error.

My code is below.

Can I not add things to and get things from the cache from a class added to my web project? Can I only use it on the code behind pages of .aspx and .ascx pages?

What am I missing?

Thanks in advance,
Ryan
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Data.SqlClient;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Text;

using System.Configuration;

namespace AeroBeta2.components

{

/// <summary>

/// Summary description for Class1.

/// </summary>

public class aeroObject : System.Web.UI.Page

{

//make animals in room talk

public string talk(int messyQuotient)

{

//intialize dataset to either be filled by sproc or cache

DataSet myDs = new DataSet();

//Check to see if this has already been cached.

if (Cache["room"] == null)

{

SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

//Create Instance of adapter

SqlDataAdapter myAdapter = new SqlDataAdapter();

//Create Command to Use with the Adapter

SqlCommand myCommand = new SqlCommand();

//Set the command connection

myCommand.Connection = myConnection;

//set the command type to a stored proc

myCommand.CommandType = CommandType.StoredProcedure;

//associate the adapter with the command

myAdapter.SelectCommand = myCommand;

//Create DataSet to Fill

myCommand.CommandText = "getIsm";

//Fill the first table of the DataSet

myAdapter.Fill(myDs, "ism");

myConnection.Close();

myCommand.Dispose();

//Insert Into Cache

Cache.Insert("ism", myDs,null,System.Web.Caching.Cache.NoAbsoluteExpiration,TimeSpan.FromSeconds(5000));

}

else

{

myDs = (DataSet)Cache["ism"];

}
Reply to this message...
 
    
Rob Howard (VIP)
Hi Ryan,

Are you running ASP.NET Premium? In Beta 2 it is required to access the
Caching functionality - NOTE, that there will be no 'Premium' version
for the final version of ASP.NET. Caching will be part of the standard
install.

With a quick glance at the code, you may try adding the
System.Web.Caching namespace.=20

Note, you don't need to inherit from 'Page' to get this Cache
functionality. You should be able to access it with:
HttpCache MyCache =3D Context.Current.Cache;

Thanks
Rob

-----Original Message-----
From: Ryan Garner [mailto:Click here to reveal e-mail address]=20
Sent: Friday, January 03, 2003 1:26 PM
To: aspngcache
Subject: [aspngcache] Cache unavailable

I have created a class and added it to my ASP.Net project.

I am trying to use ASP.Net cacheing from this class, so I inherited the
System.Web.UI.Page, so that I could use it.=20

It builds okay, but when I go access the page from the browser I get a
"Cache not available" error. =20

My code is below.

Can I not add things to and get things from the cache from a class added
to my web project? Can I only use it on the code behind pages of .aspx
and .ascx pages?

What am I missing?

Thanks in advance,
Ryan
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Configuration;
namespace AeroBeta2.components
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class aeroObject : System.Web.UI.Page
{
//make animals in room talk
public string talk(int messyQuotient)
{
//intialize dataset to either be filled by sproc or cache
DataSet myDs =3D new DataSet();
//Check to see if this has already been cached.
if (Cache["room"] =3D=3D null)
{
SqlConnection myConnection =3D new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
//Create Instance of adapter
SqlDataAdapter myAdapter =3D new SqlDataAdapter();
//Create Command to Use with the Adapter
SqlCommand myCommand =3D new SqlCommand();
//Set the command connection
myCommand.Connection =3D myConnection;
//set the command type to a stored proc
myCommand.CommandType =3D CommandType.StoredProcedure;=20
//associate the adapter with the command
myAdapter.SelectCommand =3D myCommand;
//Create DataSet to Fill
myCommand.CommandText =3D "getIsm";
//Fill the first table of the DataSet
myAdapter.Fill(myDs, "ism");
myConnection.Close();
myCommand.Dispose();
//Insert Into Cache
Cache.Insert("ism",
myDs,null,System.Web.Caching.Cache.NoAbsoluteExpiration,TimeSpan.FromSec
onds(5000));
}=20
else
{
myDs =3D (DataSet)Cache["ism"];
}
| [aspngcache] member Click here to reveal e-mail address =3D YOUR ID |
http://www.aspfriends.com/aspfriends/aspngcache.asp =3D JOIN/QUIT=20

Reply to this message...
 
    
Ryan Garner
I am not sure if I am using the Premiun buid. What I do know is that I am
able to access the cache from regular webForm pages using Cache["whatever"]
without using the System.Web.Caching namespace. Why is that?

I added the namespace to my class and used this code to test. Is this want
you meant?

using System;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

using System.Web.Caching;

namespace AeroBeta2.components

{

public class testObject

{

//make animals in room talk

public string talk(int messyQuotient)

{

HttpCache MyCache = Context.Current.Cache;
if (MyCache["room"]!=null)
{
string test = "cache working";
return test;
}

Regardless, I get a build error saying "The type or namespace name
'HttpCache' could not be found."

I obviously need to do some more reading on .Net caching. Does this have to
do with the Premium build issue you discussed?

Thanks for your help,
Ryan

----- Original Message -----
From: "Rob Howard" <Click here to reveal e-mail address>
To: "aspngcache" <Click here to reveal e-mail address>
Sent: Thursday, January 03, 2002 5:05 PM
Subject: [aspngcache] RE: Cache unavailable

Hi Ryan,

Are you running ASP.NET Premium? In Beta 2 it is required to access the
Caching functionality - NOTE, that there will be no 'Premium' version
for the final version of ASP.NET. Caching will be part of the standard
install.

With a quick glance at the code, you may try adding the
System.Web.Caching namespace.

Note, you don't need to inherit from 'Page' to get this Cache
functionality. You should be able to access it with:
HttpCache MyCache = Context.Current.Cache;

Thanks
Rob

-----Original Message-----
From: Ryan Garner [mailto:Click here to reveal e-mail address]
Sent: Friday, January 03, 2003 1:26 PM
To: aspngcache
Subject: [aspngcache] Cache unavailable

I have created a class and added it to my ASP.Net project.

I am trying to use ASP.Net cacheing from this class, so I inherited the
System.Web.UI.Page, so that I could use it.

It builds okay, but when I go access the page from the browser I get a
"Cache not available" error.

My code is below.

Can I not add things to and get things from the cache from a class added
to my web project? Can I only use it on the code behind pages of .aspx
and .ascx pages?

What am I missing?

Thanks in advance,
Ryan
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Configuration;
namespace AeroBeta2.components
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class aeroObject : System.Web.UI.Page
{
//make animals in room talk
public string talk(int messyQuotient)
{
//intialize dataset to either be filled by sproc or cache
DataSet myDs = new DataSet();
//Check to see if this has already been cached.
if (Cache["room"] == null)
{
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
//Create Instance of adapter
SqlDataAdapter myAdapter = new SqlDataAdapter();
//Create Command to Use with the Adapter
SqlCommand myCommand = new SqlCommand();
//Set the command connection
myCommand.Connection = myConnection;
//set the command type to a stored proc
myCommand.CommandType = CommandType.StoredProcedure;
//associate the adapter with the command
myAdapter.SelectCommand = myCommand;
//Create DataSet to Fill
myCommand.CommandText = "getIsm";
//Fill the first table of the DataSet
myAdapter.Fill(myDs, "ism");
myConnection.Close();
myCommand.Dispose();
//Insert Into Cache
Cache.Insert("ism",
myDs,null,System.Web.Caching.Cache.NoAbsoluteExpiration,TimeSpan.FromSec
onds(5000));
}
else
{
myDs = (DataSet)Cache["ism"];
}
| [aspngcache] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/aspngcache.asp = JOIN/QUIT

| [aspngcache] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngcache.asp = JOIN/QUIT

Reply to this message...
 
    
Rob Howard (VIP)
I'm sorry Ryan, my mistake.

Try:

Cache MyCache =3D Context.Current.Cache;

Thanks
Rob

-----Original Message-----
From: Ryan Garner [mailto:Click here to reveal e-mail address]=20
Sent: Friday, January 03, 2003 2:34 PM
To: aspngcache
Subject: [aspngcache] RE: Cache unavailable

I am not sure if I am using the Premiun buid. What I do know is that I
am able to access the cache from regular webForm pages using
Cache["whatever"] without using the System.Web.Caching namespace. Why
is that?

I added the namespace to my class and used this code to test. Is this
want you meant?

using System;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

using System.Web.Caching;

namespace AeroBeta2.components

{

public class testObject

{

//make animals in room talk

public string talk(int messyQuotient)

{

HttpCache MyCache =3D Context.Current.Cache;
if (MyCache["room"]!=3Dnull)
{
string test =3D "cache working";
return test;
}

Regardless, I get a build error saying "The type or namespace name
'HttpCache' could not be found."

I obviously need to do some more reading on .Net caching. Does this
have to do with the Premium build issue you discussed?

Thanks for your help,
Ryan

----- Original Message -----
From: "Rob Howard" <Click here to reveal e-mail address>
To: "aspngcache" <Click here to reveal e-mail address>
Sent: Thursday, January 03, 2002 5:05 PM
Subject: [aspngcache] RE: Cache unavailable

Hi Ryan,

Are you running ASP.NET Premium? In Beta 2 it is required to access the
Caching functionality - NOTE, that there will be no 'Premium' version
for the final version of ASP.NET. Caching will be part of the standard
install.

With a quick glance at the code, you may try adding the
System.Web.Caching namespace.

Note, you don't need to inherit from 'Page' to get this Cache
functionality. You should be able to access it with: HttpCache MyCache =
=3D
Context.Current.Cache;

Thanks
Rob

-----Original Message-----
From: Ryan Garner [mailto:Click here to reveal e-mail address]
Sent: Friday, January 03, 2003 1:26 PM
To: aspngcache
Subject: [aspngcache] Cache unavailable

I have created a class and added it to my ASP.Net project.

I am trying to use ASP.Net cacheing from this class, so I inherited the
System.Web.UI.Page, so that I could use it.

It builds okay, but when I go access the page from the browser I get a
"Cache not available" error.

My code is below.

Can I not add things to and get things from the cache from a class added
to my web project? Can I only use it on the code behind pages of .aspx
and .ascx pages?

What am I missing?

Thanks in advance,
Ryan
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Configuration;
namespace AeroBeta2.components
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class aeroObject : System.Web.UI.Page
{
//make animals in room talk
public string talk(int messyQuotient)
{
//intialize dataset to either be filled by sproc or cache DataSet myDs =
=3D
new DataSet(); //Check to see if this has already been cached. if
(Cache["room"] =3D=3D null) { SqlConnection myConnection =3D new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
//Create Instance of adapter
SqlDataAdapter myAdapter =3D new SqlDataAdapter();
//Create Command to Use with the Adapter
SqlCommand myCommand =3D new SqlCommand();
//Set the command connection
myCommand.Connection =3D myConnection;
//set the command type to a stored proc
myCommand.CommandType =3D CommandType.StoredProcedure; //associate the
adapter with the command myAdapter.SelectCommand =3D myCommand; //Create
DataSet to Fill myCommand.CommandText =3D "getIsm"; //Fill the first =
table
of the DataSet myAdapter.Fill(myDs, "ism"); myConnection.Close();
myCommand.Dispose(); //Insert Into Cache Cache.Insert("ism",
myDs,null,System.Web.Caching.Cache.NoAbsoluteExpiration,TimeSpan.FromSec
onds(5000));
}
else
{
myDs =3D (DataSet)Cache["ism"];
}
| [aspngcache] member Click here to reveal e-mail address =3D YOUR ID |
http://www.aspfriends.com/aspfriends/aspngcache.asp =3D JOIN/QUIT

| [aspngcache] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.aspfriends.com/aspfriends/aspngcache.asp =3D JOIN/QUIT

| [aspngcache] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.aspfriends.com/aspfriends/aspngcache.asp =3D JOIN/QUIT

Reply to this message...
 
    
Brian Bilbro (VIP)
That's because creating a class and inheriting from the Page class doesn't
populate the properties. ASP.NET does that for the asp.net page (or User
control, etc...) that it is runnning. If you want the cache object you'll
need to pass the cache object to your class from the asp.net page (or user
control, etc...)...or better yet, just pass the HttpContext and you'll have
everything available in your class.

For example:

You Class Page:
--------------------------------------------------------
using System;
using System.Web;

public class Class1
{
System.Web.HttpContext m_objContext;

public Class1(System.Web.HttpContext objContext)
{
m_objContext = objContext;
}
public void SomeMethod(String item)
{

m_objContext.Cache.Insert("ism",item,null,System.Web.Caching.Cache.NoAbsolut
eExpiration,TimeSpan.FromSeconds(5000));
}
}

You ASP.NET Page:
--------------------------------------------------------

<SCRIPT RUNAT=SERVER>
public void Page_Load(Object s, EventArgs e)
{
Class1 objClass = new Class1(this.Context);
objClass.SomeMethod("Foobar");
}
</SCRIPT>

HTHs,
Brian

[Original message clipped]

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

Reply to this message...
 
 
System.Configuration.ConfigurationSettings
System.Data.CommandType
System.Data.DataSet
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.EventArgs
System.Runtime.Remoting.Contexts.Context
System.TimeSpan
System.Web.Caching.Cache
System.Web.HttpContext
System.Web.UI.Page




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification