cache in class file

Discussion in 'ASP .Net' started by hansiman, Nov 26, 2004.

  1. hansiman

    hansiman Guest

    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?
    hansiman, Nov 26, 2004
    #1
    1. Advertising

  2. hansiman

    Karl Seguin Guest

    Try System.Web.HttpRuntime.Cache

    Karl

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


    "hansiman" <> wrote in message
    news:...
    > 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?
    >
    >
    Karl Seguin, Nov 26, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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?
    >
    >
    Kevin Spencer, Nov 27, 2004
    #3
  4. hansiman

    hansiman Guest

    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
    hansiman, Nov 29, 2004
    #4
  5. hansiman

    Karl Seguin Guest

    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" <> wrote in message
    news:...
    > 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

    >
    Karl Seguin, Nov 29, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Nokes

    Cache::Cache Stale Segments

    Jeff Nokes, Sep 30, 2003, in forum: Perl
    Replies:
    0
    Views:
    570
    Jeff Nokes
    Sep 30, 2003
  2. DesignerX

    Page.Cache vs HttpContext.Current.Cache

    DesignerX, Jan 20, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    8,243
    vMike
    Jan 20, 2004
  3. =?Utf-8?B?b25l?=
    Replies:
    1
    Views:
    5,280
    Karl Seguin [MVP]
    Mar 8, 2006
  4. Sergey via DotNetMonster.com

    ASP.NET Cache vs Window System Cache

    Sergey via DotNetMonster.com, Nov 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    474
    Sergey via DotNetMonster.com
    Nov 15, 2006
  5. John
    Replies:
    2
    Views:
    1,178
Loading...

Share This Page