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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

617 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