Clunky Cache Code Conundrum?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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)Cache["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


    Jim Owen Guest

  2. Similar Questions and Discussions

    1. update conundrum
      Hey, I have a slight issue on my hands and don't know how to approach it. Here's my situation: I have a form which allows the user to update...
    2. Cache a user control based on a Property in the code behind.
      I have a user control that is placed on every page to provide a menu system, logout/login buttons etc. This contect varies in depending on the...
    3. XML Socket - Header conundrum...
      I'm desperately trying to found out how to add a header to my socket message sends. I'm communicating via flash to a c++ server, and of course all...
    4. color conundrum
      Is there any speedy way to replace either black or white in an image with another color? "Replace color" only gives shades of gray as options, and...
    5. keyboard conundrum
      Alan Coopersmith <alanc@alum.calberkeley.org> wrote in message news:<bd5tvj$2omc$3@agate.berkeley.edu>... If not using XKB, the offset is So in...
  3. #2

    Default 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
    [url]http://Steve.Orr.net[/url]


    "Jim Owen" <jkoseattle@comcast.net> wrote in message
    news:u9nnXxPQDHA.3700@tk2msftngp13.phx.gbl...
    > 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)Cache["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 Guest

  4. #3

    Default 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.Page, add that to it, and inherit that class for all your
    Pages that need it?

    HTH,

    Kevin Spencer
    Microsoft FrontPage MVP
    Internet Developer
    [url]http://www.takempis.com[/url]
    Big things are made up of
    lots of Little things.

    "Jim Owen" <jkoseattle@comcast.net> wrote in message
    news:u9nnXxPQDHA.3700@tk2msftngp13.phx.gbl...
    > 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)Cache["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
    >
    >

    Kevin Spencer Guest

  5. #4

    Default 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.Current == 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
    [url]www.aspNetEmail.com[/url]


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

    > Thanks for the advice. I tried what you suggested, but I have two
    questions:
    >
    > 1) When I try this, I get a compile error stating "The name 'Cache' does
    not
    > exist in the class or namespace MyNameSpace.MyClass". This is why I
    assumed
    > 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
    null?
    >
    > Thanks again!
    >
    > - Jim Owen
    > 206-501-6936
    "Jim Owen" <jkoseattle@comcast.net> wrote in message
    news:u9nnXxPQDHA.3700@tk2msftngp13.phx.gbl...
    > 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)Cache["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
    >
    >

    dave wanta Guest

  6. #5

    Default Re: Clunky Cache Code Conundrum?

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

    hth,
    Dave
    [url]www.aspNetEmail.com[/url]




    "dave wanta" <nospam@nospam.com> wrote in message
    news:epNLkHYQDHA.2676@TK2MSFTNGP10.phx.gbl...
    > Hi Jim,
    >
    > You need to import the System.Web namespace at the top of your code.
    >
    > I always check for HttpContext.Current == 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
    > [url]www.aspNetEmail.com[/url]
    >
    >
    > ----- Original Message -----
    > From: "Jim Owen" <jkoseattle@comcast.net>
    > Sent: Thursday, July 03, 2003 11:26 AM
    > Subject: Re: Clunky Cache Code Conundrum?
    >
    >
    > > Thanks for the advice. I tried what you suggested, but I have two
    > questions:
    > >
    > > 1) When I try this, I get a compile error stating "The name 'Cache' does
    > not
    > > exist in the class or namespace MyNameSpace.MyClass". This is why I
    > assumed
    > > 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
    > null?
    > >
    > > Thanks again!
    > >
    > > - Jim Owen
    > > 206-501-6936
    >
    > "Jim Owen" <jkoseattle@comcast.net> wrote in message
    > news:u9nnXxPQDHA.3700@tk2msftngp13.phx.gbl...
    > > 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)Cache["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
    > >
    > >
    >
    >

    dave wanta Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139