Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > cache in class file

Reply
Thread Tools

cache in class file

 
 
hansiman
Guest
Posts: n/a
 
      11-26-2004
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?


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      11-26-2004
Try System.Web.HttpRuntime.Cache

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"hansiman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>



 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      11-27-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>



 
Reply With Quote
 
hansiman
Guest
Posts: n/a
 
      11-29-2004
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


 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      11-29-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET Cache vs Window System Cache Sergey via DotNetMonster.com ASP .Net 0 11-15-2006 03:33 PM
client-side cache vs server-side cache vs ajax vs asp.net callback =?Utf-8?B?b25l?= ASP .Net 1 03-08-2006 12:25 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Page.Cache vs HttpContext.Current.Cache DesignerX ASP .Net 5 01-20-2004 10:55 PM
Cache::Cache Stale Segments Jeff Nokes Perl 0 09-30-2003 04:34 PM



Advertisments