> Hello all. We're doing a site with teams and their members. We've got a
page
where we need to display people according to who belongs to a which team.
I've heard that nested loops are bad, but what's the alternative? Would a
group-by clause in the SELECT do the trick? Right now we're doing:
(pseudo-code)---------------------------------
For each team
print team name
For each peson
print person name
Next
Next
Yes, a group by clause would do the trick, but using a group-by clause and
then caching the output would do the trick, better:
If IsCacheExpired( CacheDataKey, CacheExpireKey, ExpireInterval) Then
Dim LastTeam
For Each TeamMember
If LastTeam <> TeamMember.Team Then
Print TeamMember.Team Name
LastTeam = TeamMember.Team
End If
Print TeamMeber.Perso nName
Next
End If
Assuming here that IsCacheExpired( ) checks an Application (or session
depending on the scope) variable to see if the cache is expired.
IsCacheExpired uses the CacheDataKey to hold the actual value in
Application, and uses CacheExpireKey to check if the cache needs to be
refreshed, and uses ExpireInterval to calculate the next expire date. You
may also want to keep a list of Keys around incase you want to release the
entire cache when data is written to the database. We also use several
Constants to indicate the refresh interval. For example:
Const CRI_FAST = 1 '// 1 hour
Const CRI_SLOW = 6 '// 6 hours
Const CRI_DAY = 23 '// 1 day
This allows us to change the meaning of a FAST refresh without looking
through every line of code to change a 1 to a 2. Our algorithm uses hours as
the unit of measure, but that is just our implementation.
An even better way to do this would be to save the keys in some sort of
resource, such as an XML file. This way, the refresh interval, CacheDataKey,
and CacheExpire key will be bound together by one single ID, and can be
referenced as such. Then you would just need a list of constants for the
ID's.
If you are doing performance tweaking, I highly recomend this page:
http://msdn.microsoft.com/library/de...ml/asptips.asp
And this one for String optimizations:
http://msdn.microsoft.com/library/de...aspstrcatn.asp
And this one for ADO & SQL:
http://msdn.microsoft.com/library/de...l/BestPrac.asp
HTH,
Jeremy