How do you use Cache in a class file

Posted on 2011-02-19
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"
Question by:mj168
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
LVL 16

Expert Comment

ID: 34933570

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.


Author Comment

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

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

Expert Comment

ID: 34934713

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

import System.Web.Caching

Author Comment

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:

There is Insert option.
LVL 16

Accepted Solution

BurnieP earned 250 total points
ID: 34937765

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 :


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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