473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

cache in class file

in a class file (utils.vb) I'm trying to use cache, but get an error!
I've tried to add imports cache namespace to utils.vb - but it does
not work. What am I doing wrong?
Nov 18 '05 #1
4 1479
Try System.Web.HttpRuntime.Cache

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"hansiman" <ha***@hotmail.com> wrote in message
news:tl********************************@4ax.com...
in a class file (utils.vb) I'm trying to use cache, but get an error!
I've tried to add imports cache namespace to utils.vb - but it does
not work. What am I doing wrong?

Nov 18 '05 #2
System.Web.HttpContext.Current.Cache will return the current Cache from a
class.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"hansiman" <ha***@hotmail.com> wrote in message
news:tl********************************@4ax.com...
in a class file (utils.vb) I'm trying to use cache, but get an error!
I've tried to add imports cache namespace to utils.vb - but it does
not work. What am I doing wrong?

Nov 18 '05 #3
Thanks... coming from classic asp I often have a hard time figuring
out what namespaces to specify in the "imports" sesion of a class
file.

Now, for instance, I need to use session(X) in the same class file,
and get the same type of "syntax error". How do I find out what
namespaces to declare?
On Fri, 26 Nov 2004 18:32:42 -0500, "Karl Seguin" <karl REMOVE @
REMOVE openmymind REMOVEMETOO . ANDME net> wrote:
Try System.Web.HttpRuntime.Cache

Karl


Nov 18 '05 #4
There's no easy way to know where a class resides (except for searching
through the online help).

Normally when you are in codebehind, Session is available as a property of
the Control class your Pages, User Controls and Server Controls inherit
from. In reality however, the real property is exposed by the HttpContext
object. Each request runs within an HttpContext. You can get a reference
to the current context being executed via System.Web.HttpContext.Current,
and from that access the Session:

dim context as HttpContext = HttpContext.Current
Context.Session.Add("SomeNewSession", "SomeId")

note howeverthat HttpContext.Current could return null/nothing if the class
file isn't being used from a web request (say for example, if you were
planning on using it for a windows form as well). Since this probably won't
be the case, no problem...but it's also good practice to check things
properly:

dim context as HttpContext = HttpContext.Current
if context is nothing then
throw new ApplicationException("This method must be called within a web
context")
end if

is a simple option :)

You might wanna check: http://openmymind.net/DataStorage/index.html I have
a little blurb about doing just this (though there isn't more to it that
what I've said here).

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"hansiman" <ha***@hotmail.com> wrote in message
news:4p********************************@4ax.com...
Thanks... coming from classic asp I often have a hard time figuring
out what namespaces to specify in the "imports" sesion of a class
file.

Now, for instance, I need to use session(X) in the same class file,
and get the same type of "syntax error". How do I find out what
namespaces to declare?
On Fri, 26 Nov 2004 18:32:42 -0500, "Karl Seguin" <karl REMOVE @
REMOVE openmymind REMOVEMETOO . ANDME net> wrote:
Try System.Web.HttpRuntime.Cache

Karl

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ben | last post by:
Hi all, I have written a web server that listens for requests: class MyHandler(BaseHTTPRequestHandler): def do_GET(self): if (self.path)=='/': data=makeList() else:
2
by: Showjumper | last post by:
If i use the cache class in the global asax file in the session sub, can i override for an individual page that has content that will be changing more frequently than the rest of the site? Would i...
7
by: moondaddy | last post by:
I want to dynamically create a JavaScript file and cache it on the client for re-use. I know how to write javascript to a web page from the code behind, but I don't know how to actually create a...
7
by: A.M | last post by:
Hi, How can I change the duration of user control's cache inside asp.net's C# code? Any help would be apprecited, Alan
5
by: Darrel | last post by:
I thought this warranted a new thread. Yesterday I asked about access relatively static content...is it better to read from the DB, or just grab a text file. It was suggested that I use the DB...
3
by: Alex | last post by:
Hi I am opening an xml file into a dataset and then converting it to a namevaluecollection and then saving the collection in the cache for use later. The cache dependency is set to the xml...
11
by: Steve Franks | last post by:
I see several reference to using the ASP.NET 2.0 Cache object in C# where the documentation just shows snippets like this: if (Cache == null) ... do something However when I use this code in a...
1
by: Keithb | last post by:
Is there any way to create a cache dependency based on a folder in the server file system? My application needs to drop a table in the cache if any files are changed in a server file folder or its...
0
by: Hypnotik | last post by:
My program is to simulate cache memory. I read in the info from 2 external files, 1) access 2) data in memory. When I read the information in I display the info...and it is all correct. However...
7
by: Andrew Jocelyn | last post by:
Hi I'm running an ASP.NET web application under IIS. I'm inserting a cache object with a file based CacheDependency. I've noticed that when the file changes the Cache object is not always...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.