Solved

How do you use Cache in a class file

Posted on 2011-02-19
5
334 Views
Last Modified: 2012-05-11
I am having a problem using Cache in my class file. It is an ASP.Net application using VB.NET.

Below is the header in the file:

Imports Microsoft.VisualBasic


Below is the code I am using in an attempt to insert an item into the Cache.

Cache.Insert("FieldName", "Value")

The above generates an error whose description says the below:

"Reference to a non-shared member requires an object reference"
0
Comment
Question by:mj168
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:BurnieP
ID: 34933570
Hi,

In what class are you trying to use Cache?  Are you in a Page or in a simple class?

Using System.Web.HttpContext.Current.Cache might solve your problem.

0
 

Author Comment

by:mj168
ID: 34934495
It is in a seperate file from the .aspx file.

It is in a file with the extension .vb
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34934713
Ok..

Can you verify if you have the import at the top of your .vb file?  The import should be :

import System.Web.Caching
0
 

Author Comment

by:mj168
ID: 34934957
Below is what I have at the top of the .vb class file.

Imports Microsoft.VisualBasic
Imports System.Web.Caching


When I key Cache, there are only for options. They are:
Equals
NoAbsoluteExpiration
NoSlidingExpiration
ReferenceEquals

There is Insert option.
0
 
LVL 16

Accepted Solution

by:
BurnieP earned 250 total points
ID: 34937765
Hi,

I think you want to use Cache in a class file,  I thought it was in the code behind of your .aspx file.

To use Cache in a class function, use :

System.Web.HttpContext.Current.Cache
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question