Can I Use Page.Cache in a Class Library?

admin

Administrator
Staff member
I am converting a .ascx component to a class library but it accesses the Page.Cache class and when I use the following code:

Cache.Insert(whatever);

I get the following error when trying to compile the class library.

The name 'Cache' does not exist in the class or namespace 'pfus.lib.ctrlPfus'


So I add Page.Cache and it compiles, but then when i add it to my new project and run it i get Object Refrence not set to the instance of an object.

Any ideas?You need to pass in the Page reference when you call the function in your class.

Ericthanks for the quick reply!!!

When i use this code:
Cache.Insert("picklist",pickList);
Cache.Insert("htpromos",htPromos);

it doesn't build and produces the error:
An object reference is required for the nonstatic field, method, or property 'System.Web.Caching.Cache.Insert(string, object)'

and when i use Page.Cache.Insert("htPromos",htPromos);

it builds, but upon inserting the .dll into my new project and trying to run it, i get
Object Reference Not Set to the Instance of an Object...

any ideas?Dim Cache As System.Web.Caching.Cache = System.Web.HttpContext.Current.Cache

Are you declaring the cache?
Eric
 
Back
Top