Solved

How do you use Cache in a class file

Posted on 2011-02-19
5
327 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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