Ask a Question related to ASP.NET General, Design and Development.
-
Jim Owen #1
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
-
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... -
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... -
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... -
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... -
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... -
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
[url]http://Steve.Orr.net[/url]
"Jim Owen" <jkoseattle@comcast.net> wrote in message
news:u9nnXxPQDHA.3700@tk2msftngp13.phx.gbl...like:> 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 somethingmethod>
> MyDataType LocalVar = (MyDataType)Cache["MyData"];
>
> Which works fine, but I'm having to put that code at the top of everyelegant> in my form that uses the cached data. It seems there must be a moreit> way to do this. I don't think I can put it in a form-level field, becausemethod> doesn't persist across posts, and I can't wrap the code into a staticbe> somewhere else because as I understand it the application cache can only> access from forms, and not from .cs files.
>
> Any ideas?
>
> --
> - Jim Owen
> 206-501-6936
>
>
Steve C. Orr, MCSD Guest
-
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.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...like:> 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 somethingmethod>
> MyDataType LocalVar = (MyDataType)Cache["MyData"];
>
> Which works fine, but I'm having to put that code at the top of everyelegant> in my form that uses the cached data. It seems there must be a moreit> way to do this. I don't think I can put it in a form-level field, becausemethod> doesn't persist across posts, and I can't wrap the code into a staticbe> somewhere else because as I understand it the application cache can only> access from forms, and not from .cs files.
>
> Any ideas?
>
> --
> - Jim Owen
> 206-501-6936
>
>
Kevin Spencer Guest
-
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.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?
questions:> Thanks for the advice. I tried what you suggested, but I have twonot>
> 1) When I try this, I get a compile error stating "The name 'Cache' doesassumed> exist in the class or namespace MyNameSpace.MyClass". This is why Inull?> 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"Jim Owen" <jkoseattle@comcast.net> wrote in message>
> Thanks again!
>
> - Jim Owen
> 206-501-6936
news:u9nnXxPQDHA.3700@tk2msftngp13.phx.gbl...like:> 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 somethingmethod>
> MyDataType LocalVar = (MyDataType)Cache["MyData"];
>
> Which works fine, but I'm having to put that code at the top of everyelegant> in my form that uses the cached data. It seems there must be a moreit> way to do this. I don't think I can put it in a form-level field, becausemethod> doesn't persist across posts, and I can't wrap the code into a staticbe> somewhere else because as I understand it the application cache can only> access from forms, and not from .cs files.
>
> Any ideas?
>
> --
> - Jim Owen
> 206-501-6936
>
>
dave wanta Guest
-
dave wanta #5
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...in> 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?
>
>> questions:> > Thanks for the advice. I tried what you suggested, but I have two> not> >
> > 1) When I try this, I get a compile error stating "The name 'Cache' does> assumed> > exist in the class or namespace MyNameSpace.MyClass". This is why I> null?> > 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>> >
> > 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 objectsbecause> like:> > the cache. The only way I can think of to do this is to call something> method> >
> > MyDataType LocalVar = (MyDataType)Cache["MyData"];
> >
> > Which works fine, but I'm having to put that code at the top of every> elegant> > in my form that uses the cached data. It seems there must be a more> > way to do this. I don't think I can put it in a form-level field,> it> method> > doesn't persist across posts, and I can't wrap the code into a static> be> > somewhere else because as I understand it the application cache can only>> > access from forms, and not from .cs files.
> >
> > Any ideas?
> >
> > --
> > - Jim Owen
> > 206-501-6936
> >
> >
>
dave wanta Guest



Reply With Quote

