473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

cache at the page or at the DAL?

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 then I thought it would be cleaner to
maybe at the Cache code directly in the DAL. So, for example I might have a
DAL method to get products that looks like this:

public DataSet GetProducts()
{
if(Cache["prodData"])
{
return (DataSet)Cache["prodData"];
}
else
{
DataSet dsBuff;
//.... code to get stuff from the DB - fill the dsBuff with it

Cache["prodData"] = dsBuff;
return dsBuff;
}
}
(that was not real code, I just typed it, so if there are typos.. please
disgregard)
I'm curious if this is how you guys are doing things? Is there anything
wrong with doing it this way?

your thoughts please...

- Steve

Nov 18 '05 #1
5 3202
You're probably better off to implement caching outside the DAL. If you
cache in the DAL, what happens if you need to change the caching mechanism.
You then have to verify that all the dependant functions behave properly,
not to mention you then end up with a very specific set of DAL functions.
You could implement a caching engine to call the DAL, which would unify your
caching functions and at the same time give you the flexibility to having
cached and non-cached data (or cached data that may be depednent on
different events/files/functions) from one clean DAL.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"sklett" <as**@fkd.com> wrote in message
news:ew***************@TK2MSFTNGP12.phx.gbl...
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 then I thought it would be cleaner to maybe at the Cache code directly in the DAL. So, for example I might have a DAL method to get products that looks like this:

public DataSet GetProducts()
{
if(Cache["prodData"])
{
return (DataSet)Cache["prodData"];
}
else
{
DataSet dsBuff;
//.... code to get stuff from the DB - fill the dsBuff with it

Cache["prodData"] = dsBuff;
return dsBuff;
}
}
(that was not real code, I just typed it, so if there are typos.. please
disgregard)
I'm curious if this is how you guys are doing things? Is there anything
wrong with doing it this way?

your thoughts please...

- Steve

Nov 18 '05 #2
General rule of thumb: Cache your data at the scope in which it is needed.
In other words, if, for example, you have data that is not specific to any
user, but is used in many pages, cache it at the Application level. If it is
specific to a user, but used across many pages, cache it at the Session
level. If it is only used on a single Paage, either don't cache it, or cache
it in ViewState.

The principle here is to minimize memory usage, and not persist any data
that is no longer needed.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"sklett" <as**@fkd.com> wrote in message
news:ew*************@TK2MSFTNGP12.phx.gbl...
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 then I thought it would be cleaner to maybe at the Cache code directly in the DAL. So, for example I might have a DAL method to get products that looks like this:

public DataSet GetProducts()
{
if(Cache["prodData"])
{
return (DataSet)Cache["prodData"];
}
else
{
DataSet dsBuff;
//.... code to get stuff from the DB - fill the dsBuff with it

Cache["prodData"] = dsBuff;
return dsBuff;
}
}
(that was not real code, I just typed it, so if there are typos.. please
disgregard)
I'm curious if this is how you guys are doing things? Is there anything
wrong with doing it this way?

your thoughts please...

- Steve

Nov 18 '05 #3
General rule of thumb: Cache your data at the scope in which it is needed.
In other words, if, for example, you have data that is not specific to any
user, but is used in many pages, cache it at the Application level. If it is
specific to a user, but used across many pages, cache it at the Session
level. If it is only used on a single Paage, either don't cache it, or cache
it in ViewState.

The principle here is to minimize memory usage, and not persist any data
that is no longer needed.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"sklett" <as**@fkd.com> wrote in message
news:ew*************@TK2MSFTNGP12.phx.gbl...
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 then I thought it would be cleaner to maybe at the Cache code directly in the DAL. So, for example I might have a DAL method to get products that looks like this:

public DataSet GetProducts()
{
if(Cache["prodData"])
{
return (DataSet)Cache["prodData"];
}
else
{
DataSet dsBuff;
//.... code to get stuff from the DB - fill the dsBuff with it

Cache["prodData"] = dsBuff;
return dsBuff;
}
}
(that was not real code, I just typed it, so if there are typos.. please
disgregard)
I'm curious if this is how you guys are doing things? Is there anything
wrong with doing it this way?

your thoughts please...

- Steve

Nov 18 '05 #4
What I have been doing is storing all the product data (the company has 10
products, so there is not much) in a DataSet, I then cache that. When a
user chooses a product from the product listing page, I use the Select
method of a table in the DataSet to get just the data I want.

I made the site's admin all web based, when a product is added or modified,
I empty the cache, then the next time product data is needed, I hit the DB
and fill the cache again.

I hear what you are saying though. I'm just starting to have a hard time
decided if I need to even cache stuff, the traffic is so low, maybe it would
be cleaner to hit the DB each time.

Need to think and plan more ;)

Thanks both of you for the responses, they are valuable.

-Steve

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
General rule of thumb: Cache your data at the scope in which it is needed.
In other words, if, for example, you have data that is not specific to any
user, but is used in many pages, cache it at the Application level. If it is specific to a user, but used across many pages, cache it at the Session
level. If it is only used on a single Paage, either don't cache it, or cache it in ViewState.

The principle here is to minimize memory usage, and not persist any data
that is no longer needed.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"sklett" <as**@fkd.com> wrote in message
news:ew*************@TK2MSFTNGP12.phx.gbl...
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 then I thought it would be

cleaner to
maybe at the Cache code directly in the DAL. So, for example I might
have a
DAL method to get products that looks like this:

public DataSet GetProducts()
{
if(Cache["prodData"])
{
return (DataSet)Cache["prodData"];
}
else
{
DataSet dsBuff;
//.... code to get stuff from the DB - fill the dsBuff with it

Cache["prodData"] = dsBuff;
return dsBuff;
}
}
(that was not real code, I just typed it, so if there are typos.. please
disgregard)
I'm curious if this is how you guys are doing things? Is there anything
wrong with doing it this way?

your thoughts please...

- Steve


Nov 18 '05 #5
What I have been doing is storing all the product data (the company has 10
products, so there is not much) in a DataSet, I then cache that. When a
user chooses a product from the product listing page, I use the Select
method of a table in the DataSet to get just the data I want.

I made the site's admin all web based, when a product is added or modified,
I empty the cache, then the next time product data is needed, I hit the DB
and fill the cache again.

I hear what you are saying though. I'm just starting to have a hard time
decided if I need to even cache stuff, the traffic is so low, maybe it would
be cleaner to hit the DB each time.

Need to think and plan more ;)

Thanks both of you for the responses, they are valuable.

-Steve

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
General rule of thumb: Cache your data at the scope in which it is needed.
In other words, if, for example, you have data that is not specific to any
user, but is used in many pages, cache it at the Application level. If it is specific to a user, but used across many pages, cache it at the Session
level. If it is only used on a single Paage, either don't cache it, or cache it in ViewState.

The principle here is to minimize memory usage, and not persist any data
that is no longer needed.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"sklett" <as**@fkd.com> wrote in message
news:ew*************@TK2MSFTNGP12.phx.gbl...
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 then I thought it would be

cleaner to
maybe at the Cache code directly in the DAL. So, for example I might
have a
DAL method to get products that looks like this:

public DataSet GetProducts()
{
if(Cache["prodData"])
{
return (DataSet)Cache["prodData"];
}
else
{
DataSet dsBuff;
//.... code to get stuff from the DB - fill the dsBuff with it

Cache["prodData"] = dsBuff;
return dsBuff;
}
}
(that was not real code, I just typed it, so if there are typos.. please
disgregard)
I'm curious if this is how you guys are doing things? Is there anything
wrong with doing it this way?

your thoughts please...

- Steve


Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
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...
1
by: MilanB | last post by:
Hello Is it possible to cache page fragment (in UserControl), and not a whole page on client side? Thanks
18
by: Mark | last post by:
Hello. I am looking for a way to download and cache a web page that the user has not yet requested, and write the web page to the browser cache without displaying it. My intention is to improve...
11
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...
5
by: Stan SR | last post by:
Hi, Some newbie questions.. :-) First, what is the namespace to use for the Cache class ? When I use this bit of code I get an error if (Cache==null) Cache.Insert("myUserList",userlist);...
4
by: Peter Bremer | last post by:
Hi all, I've got a form which lists all members of a club, with checkboxes to select them. The form offers functions to delete selected members, send email, etc. Now I want write some code to...
0
by: =?Utf-8?B?bGl1eGluZmVpaHU=?= | last post by:
Hi, I use post way realization page postback this am must,How realizesunder the post way controls postback continuously to be unable to findthe solution the method to hope can obtain master's help...
1
by: amit sinha | last post by:
I did developed a code in VS2005 aspx file which opens pop up window on button click javascript window.showModalDialog(popwin.aspx? cCODE='cd',winprop) Now as popwin.aspx take long time to...
2
by: marconline | last post by:
Hi everyone and thanks for your help. My web form is formed by a master page, which contains some web user controls. The same web form contains other web user controls. This page is very slow....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.