PC Review


Reply
Thread Tools Rate Thread

Application Variables / Database Caching - Best Practice

 
 
Duncan Welch
Guest
Posts: n/a
 
      26th Jul 2004
Good morning,

I have a classic ASP app that I'm converting to .NET. In the existing app
when accessing infrequntly changed data, it reads a database once a day, and
saves the results in an application variable.

I'm trying to replicate this in .NET, but I'm using a data access layer
(DAL) that's in a seperate project. Obviously, the DAL can't see the
application variables. I was thinking of passing the application state in
the constructor, but this seems like overkill.

Can someone please point me in the direction of a "best practices" guide to
converting legacy application variable caching where an external DAL is
involved, or does anyone have any strong opinions on thie best way to do
this?

Regards,

Duncan


 
Reply With Quote
 
 
 
 
Nick Malik
Guest
Posts: n/a
 
      26th Jul 2004
If the ASP app was saving data in an application variable, then "once a day"
was optimistic... the application variable would time out and be destroyed
if the last user stopped using the app and no one else came in for 20
minutes. If your app is on the open internet and is reasonably popular,
then the app would remain in memory for a full 24 hours. However, an app
that is primarily used between 8 and 5 would probably time out its
application variables until the first user visits the next day.

So keeping that in mind:

I would implement a cache object using a singleton in the application. The
singleton pattern creates an object and stores it in a static variable. You
can find quite a few references on the web on creating singletons well in
C#.

This would behave similarly to the use of the app variable from your ASP
app.

Hope this helps,
--- Nick

"Duncan Welch" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Good morning,
>
> I have a classic ASP app that I'm converting to .NET. In the existing app
> when accessing infrequntly changed data, it reads a database once a day,

and
> saves the results in an application variable.
>
> I'm trying to replicate this in .NET, but I'm using a data access layer
> (DAL) that's in a seperate project. Obviously, the DAL can't see the
> application variables. I was thinking of passing the application state in
> the constructor, but this seems like overkill.
>
> Can someone please point me in the direction of a "best practices" guide

to
> converting legacy application variable caching where an external DAL is
> involved, or does anyone have any strong opinions on thie best way to do
> this?
>
> Regards,
>
> Duncan
>
>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      26th Jul 2004
Hi Duncan:

In a web application, you can use HttpContext.Current to reach the
Application collection during processing of a request. I.e.:

HttpContext.Current.Application["MyAppVar"];

Since this ties the DAL to working inside of a web application, I
generally abstract away the source of the cached data with a new
class (or classes, if need be). For a web application the custom cache
class will look into the Application or Cache collections, for a forms
application it might just look into a Hashtable it owns.

HTH,

--
Scott
http://www.OdeToCode.com


On Mon, 26 Jul 2004 12:25:34 +0100, "Duncan Welch"
<(E-Mail Removed)> wrote:

>Good morning,
>
>I have a classic ASP app that I'm converting to .NET. In the existing app
>when accessing infrequntly changed data, it reads a database once a day, and
>saves the results in an application variable.
>
>I'm trying to replicate this in .NET, but I'm using a data access layer
>(DAL) that's in a seperate project. Obviously, the DAL can't see the
>application variables. I was thinking of passing the application state in
>the constructor, but this seems like overkill.
>
>Can someone please point me in the direction of a "best practices" guide to
>converting legacy application variable caching where an external DAL is
>involved, or does anyone have any strong opinions on thie best way to do
>this?
>
>Regards,
>
>Duncan
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Application Variables versus Database access Jeff Microsoft VB .NET 0 1st Dec 2006 04:34 AM
question about caching using the caching application block EL 2 =?Utf-8?B?YWhtX2VidXNpbmVzc190cg==?= Microsoft Dot NET Framework 0 19th Sep 2005 06:51 PM
declaring variables - best practice =?Utf-8?B?QW50?= Microsoft C# .NET 5 7th Jul 2005 08:38 PM
Best practice approach to caching dropdown values oj Microsoft ASP .NET 1 25th Nov 2004 01:45 AM
Declaring variables - best practice? Rob Meade Microsoft ASP .NET 2 24th Nov 2003 03:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 PM.