Clunky Cache Code Conundrum?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Owen

    Clunky Cache Code Conundrum?

    I am storing all my application data in the application cache. Anytime I
    have a method as part of an asp.net form, I need to access the objects in
    the cache. The only way I can think of to do this is to call something like:

    MyDataType LocalVar = (MyDataType)Cac he["MyData"];

    Which works fine, but I'm having to put that code at the top of every method
    in my form that uses the cached data. It seems there must be a more elegant
    way to do this. I don't think I can put it in a form-level field, because it
    doesn't persist across posts, and I can't wrap the code into a static method
    somewhere else because as I understand it the application cache can only be
    access from forms, and not from .cs files.

    Any ideas?

    --
    - Jim Owen
    206-501-6936


  • Steve C. Orr, MCSD

    #2
    Re: Clunky Cache Code Conundrum?

    I don't see anything inelegant about it.
    It's a single line of code. How could you reduce it down to anything
    significantly simpler than that?

    --
    I hope this helps,
    Steve C. Orr, MCSD



    "Jim Owen" <jkoseattle@com cast.net> wrote in message
    news:u9nnXxPQDH A.3700@tk2msftn gp13.phx.gbl...[color=blue]
    > I am storing all my application data in the application cache. Anytime I
    > have a method as part of an asp.net form, I need to access the objects in
    > the cache. The only way I can think of to do this is to call something[/color]
    like:[color=blue]
    >
    > MyDataType LocalVar = (MyDataType)Cac he["MyData"];
    >
    > Which works fine, but I'm having to put that code at the top of every[/color]
    method[color=blue]
    > in my form that uses the cached data. It seems there must be a more[/color]
    elegant[color=blue]
    > way to do this. I don't think I can put it in a form-level field, because[/color]
    it[color=blue]
    > doesn't persist across posts, and I can't wrap the code into a static[/color]
    method[color=blue]
    > somewhere else because as I understand it the application cache can only[/color]
    be[color=blue]
    > access from forms, and not from .cs files.
    >
    > Any ideas?
    >
    > --
    > - Jim Owen
    > 206-501-6936
    >
    >[/color]


    Comment

    • Kevin Spencer

      #3
      Re: Clunky Cache Code Conundrum?

      It's only one line of code, but if you want to share it among all of your
      forms, why don't you create a Class that inherits from
      System.Web.UI.P age, add that to it, and inherit that class for all your
      Pages that need it?

      HTH,

      Kevin Spencer
      Microsoft FrontPage MVP
      Internet Developer

      Big things are made up of
      lots of Little things.

      "Jim Owen" <jkoseattle@com cast.net> wrote in message
      news:u9nnXxPQDH A.3700@tk2msftn gp13.phx.gbl...[color=blue]
      > I am storing all my application data in the application cache. Anytime I
      > have a method as part of an asp.net form, I need to access the objects in
      > the cache. The only way I can think of to do this is to call something[/color]
      like:[color=blue]
      >
      > MyDataType LocalVar = (MyDataType)Cac he["MyData"];
      >
      > Which works fine, but I'm having to put that code at the top of every[/color]
      method[color=blue]
      > in my form that uses the cached data. It seems there must be a more[/color]
      elegant[color=blue]
      > way to do this. I don't think I can put it in a form-level field, because[/color]
      it[color=blue]
      > doesn't persist across posts, and I can't wrap the code into a static[/color]
      method[color=blue]
      > somewhere else because as I understand it the application cache can only[/color]
      be[color=blue]
      > access from forms, and not from .cs files.
      >
      > Any ideas?
      >
      > --
      > - Jim Owen
      > 206-501-6936
      >
      >[/color]


      Comment

      • dave wanta

        #4
        Re: Clunky Cache Code Conundrum?

        Hi Jim,

        You need to import the System.Web namespace at the top of your code.

        I always check for HttpContext.Cur rent == null because a lot of my class
        files are also used in Non- ASP.NET apps, so its more habit than anything
        else.

        hth,
        Dave



        ----- Original Message -----
        From: "Jim Owen" <jkoseattle@com cast.net>
        Sent: Thursday, July 03, 2003 11:26 AM
        Subject: Re: Clunky Cache Code Conundrum?

        [color=blue]
        > Thanks for the advice. I tried what you suggested, but I have two[/color]
        questions:[color=blue]
        >
        > 1) When I try this, I get a compile error stating "The name 'Cache' does[/color]
        not[color=blue]
        > exist in the class or namespace MyNameSpace.MyC lass". This is why I[/color]
        assumed[color=blue]
        > that the Cache could not be accessed from .cs files.
        > 2) Why do I need to test for HttpContext == null? How could it ever be[/color]
        null?[color=blue]
        >
        > Thanks again!
        >
        > - Jim Owen
        > 206-501-6936[/color]

        "Jim Owen" <jkoseattle@com cast.net> wrote in message
        news:u9nnXxPQDH A.3700@tk2msftn gp13.phx.gbl...[color=blue]
        > I am storing all my application data in the application cache. Anytime I
        > have a method as part of an asp.net form, I need to access the objects in
        > the cache. The only way I can think of to do this is to call something[/color]
        like:[color=blue]
        >
        > MyDataType LocalVar = (MyDataType)Cac he["MyData"];
        >
        > Which works fine, but I'm having to put that code at the top of every[/color]
        method[color=blue]
        > in my form that uses the cached data. It seems there must be a more[/color]
        elegant[color=blue]
        > way to do this. I don't think I can put it in a form-level field, because[/color]
        it[color=blue]
        > doesn't persist across posts, and I can't wrap the code into a static[/color]
        method[color=blue]
        > somewhere else because as I understand it the application cache can only[/color]
        be[color=blue]
        > access from forms, and not from .cs files.
        >
        > Any ideas?
        >
        > --
        > - Jim Owen
        > 206-501-6936
        >
        >[/color]


        Comment

        • dave wanta

          #5
          Re: Clunky Cache Code Conundrum?

          btw,
          make sure you reference the Cache object via "HttpContext.Cu rrent.Cache" in
          your code, not just "Cache".

          hth,
          Dave





          "dave wanta" <nospam@nospam. com> wrote in message
          news:epNLkHYQDH A.2676@TK2MSFTN GP10.phx.gbl...[color=blue]
          > Hi Jim,
          >
          > You need to import the System.Web namespace at the top of your code.
          >
          > I always check for HttpContext.Cur rent == null because a lot of my class
          > files are also used in Non- ASP.NET apps, so its more habit than anything
          > else.
          >
          > hth,
          > Dave
          > www.aspNetEmail.com
          >
          >
          > ----- Original Message -----
          > From: "Jim Owen" <jkoseattle@com cast.net>
          > Sent: Thursday, July 03, 2003 11:26 AM
          > Subject: Re: Clunky Cache Code Conundrum?
          >
          >[color=green]
          > > Thanks for the advice. I tried what you suggested, but I have two[/color]
          > questions:[color=green]
          > >
          > > 1) When I try this, I get a compile error stating "The name 'Cache' does[/color]
          > not[color=green]
          > > exist in the class or namespace MyNameSpace.MyC lass". This is why I[/color]
          > assumed[color=green]
          > > that the Cache could not be accessed from .cs files.
          > > 2) Why do I need to test for HttpContext == null? How could it ever be[/color]
          > null?[color=green]
          > >
          > > Thanks again!
          > >
          > > - Jim Owen
          > > 206-501-6936[/color]
          >
          > "Jim Owen" <jkoseattle@com cast.net> wrote in message
          > news:u9nnXxPQDH A.3700@tk2msftn gp13.phx.gbl...[color=green]
          > > I am storing all my application data in the application cache. Anytime I
          > > have a method as part of an asp.net form, I need to access the objects[/color][/color]
          in[color=blue][color=green]
          > > the cache. The only way I can think of to do this is to call something[/color]
          > like:[color=green]
          > >
          > > MyDataType LocalVar = (MyDataType)Cac he["MyData"];
          > >
          > > Which works fine, but I'm having to put that code at the top of every[/color]
          > method[color=green]
          > > in my form that uses the cached data. It seems there must be a more[/color]
          > elegant[color=green]
          > > way to do this. I don't think I can put it in a form-level field,[/color][/color]
          because[color=blue]
          > it[color=green]
          > > doesn't persist across posts, and I can't wrap the code into a static[/color]
          > method[color=green]
          > > somewhere else because as I understand it the application cache can only[/color]
          > be[color=green]
          > > access from forms, and not from .cs files.
          > >
          > > Any ideas?
          > >
          > > --
          > > - Jim Owen
          > > 206-501-6936
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...