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 4 1699
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 http://Steve.Orr.net
"Jim Owen" <jk********@comcast.net> wrote in message
news:u9**************@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
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 http://www.takempis.com
Big things are made up of
lots of Little things.
"Jim Owen" <jk********@comcast.net> wrote in message
news:u9**************@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
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 www.aspNetEmail.com
----- Original Message -----
From: "Jim Owen" <jk********@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" <jk********@comcast.net> wrote in message
news:u9**************@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
btw,
make sure you reference the Cache object via "HttpContext.Current.Cache" in
your code, not just "Cache".
hth,
Dave www.aspNetEmail.com
"dave wanta" <no****@nospam.com> wrote in message
news:ep**************@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 www.aspNetEmail.com
----- Original Message ----- From: "Jim Owen" <jk********@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" <jk********@comcast.net> wrote in message news:u9**************@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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: fatted |
last post by:
I've written a function (clean_string) to remove characters from a string,
but it looks clunky to me, and I'm sure there's a more 'C' like way of
doing it (still learning), comments and advice...
|
by: sklett |
last post by:
Hi-
I am having a hard time decided where I should be implementing my Cache
code. I store most of the DataSet's that I need in the Cache. I was doing
it in the bind method of my pages, but...
|
by: Tom.PesterDELETETHISSS |
last post by:
Hi,
I think this question requires an in depth understanding of how a browser
cache works. I hope I can reach an expert here.
I may have found a quirk in the asp.net documentation or I don't...
|
by: Andrew Morton |
last post by:
I am caching some data in VB.NET using System.Web.Caching, is it possible to
lock the cache so that other sessions attempting to access the same cache
wait when it is being updated? I have the...
|
by: R. MacDonald |
last post by:
Hello, all,
I am currently working on a .Net (VB) application that invokes routines
in unmanaged (Fortran) DLLs. The unmanaged routines then communicate
with the .Net application by means of a...
|
by: subnunciation |
last post by:
i know, this shouldnt be a conundrum right? one just shouldnt divide by
zero. but this is suddenly happening *all over* my site. after chasing
the error here and there, i simplified things down to:...
|
by: EagleRed |
last post by:
I am writing an ASP.NET 2.0 application that uses master pages. I have some
pages that must not be cached on the client. In ASP.NET 1.1 I achieved this
using metatags:
<meta...
|
by: moondaddy |
last post by:
I had to repost this because I had to update and change my msdn alias. I
will re-ask the question and clarify a few things that were not clear
before.
This code is all executed on my dev...
|
by: =?Utf-8?B?Y2F0?= |
last post by:
We recently moved an older ASP.NET 1.1 code base on to ASP.NET 2.0, .NET 3.0
and Windows 2003 Server SP2. We started experiencing the following issue with
the web cache (the code is straightforward...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |