Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2008, 11:46 AM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default cache problem

hi,

i am trying to use the cache, but when i want to add an object using the insert method, it returns object reference not set to an instance of an object, i can't figure it out yet why, if i am declaring my cache variable...

i am doing something like this:

Cache myCache = new Cache();

myCache.Insert("object", myObject);


what do you think is happening??

 
Old April 24th, 2008, 03:20 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You don't need to create in instance of the Cache in your web applications. It's just there so you can use static methods like this:

Cache.Insert("object", myObject);

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old April 24th, 2008, 04:18 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that's not working... the available methods without instantiate are: Equals, NoAbsoluteExpiration, NoSlidingExpiration and ReferenceEquals

i am doing this:

using System.Web.Caching;
...
...
...
Cache.Insert("myObject", myOtherObject);


and returns this error: An object reference is required for the nonstatic field, method, or property 'System.Web.Caching.Cache.Insert(string, object)'

 
Old April 24th, 2008, 04:36 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In what kind of project are you using this code?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old April 24th, 2008, 05:06 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it's a web project by the way...

 
Old April 25th, 2008, 01:01 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Could you provide more information? What kind of web project? Are you running this code in the Code Behind of a page? Or maybe in a code file in App_Code?

In the former case, my code should work. In the latter case, try this:

System.Web.HttpContext.Current.Cache.Insert(...);

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
about using cache benordz ASP.NET 2.0 Basics 2 April 25th, 2008 09:19 AM
image cache problem in Internet Explorer richard.york PHP How-To 16 June 10th, 2006 03:32 AM
Cache problem jeanzz83 ASP.NET 1.0 and 1.1 Basics 1 January 3rd, 2006 12:36 PM
Cache problem alton Classic ASP Basics 3 September 6th, 2004 12:37 PM
Cache problem hrishimusale Classic ASP Basics 0 August 27th, 2003 04:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.