Solved

How do you use Cache in a class file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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 …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now