473,486 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3208
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
2072
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
995
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
2177
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
12089
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
2104
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
1514
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
1370
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
1421
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
2112
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
7123
Oralloy
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,...
0
7173
jinu1996
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...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.