Solved

How do you use Cache in a class file

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

773 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