I guess in the end it comes down to personal opinion and experience. In my opinion it is really not worth caching a query like this, lets say we are dealing with 10.000 records, and you want a random record, no way that it would be cost efficient to cache it, unless memory management is not a worry.
Even when dealing with only a few records the hassle of 'caching and purging when needed' to me is not worth it, a trip to db and the query itself on MS SQL means nothing. But like I said, it's a matter of personal opinion ;-) Taco Fleur - Pacific Fox an industry leader with commercial IT experience since 1994 . http://www.pacificfox.com - Web Design and Development > -----Original Message----- > From: Jim Davis [mailto:[EMAIL PROTECTED] > Sent: Thursday, 29 September 2005 2:56 PM > To: CF-Talk > Subject: RE: Every once in a while, I feel smart. A story of > displaying a single random image. > > > > -----Original Message----- > > From: Taco Fleur [mailto:[EMAIL PROTECTED] > > Sent: Wednesday, September 28, 2005 11:47 PM > > To: CF-Talk > > Subject: RE: Every once in a while, I feel smart. A story of > > displaying a single random image. > > > > Hmm, sorry to break your bubbles but both solutions are very > > inefficient. > > > > The best thing to do is (in MS SQL) > > > > SELECT TOP 1 * > > FROM yourTable > > ORDER BY NEWID() > > > > That will give you a random record every time and you are not > > transferring a whole record set over the network. > > Well... it's not really a random value (but close enough for > practical purposes). ;^) > > But forgetting that I think we're both making assumptions > about the usage. I was under the impression from the original > poster that this random image would be displayed a lot - so > using a cached query and doing what I (or the original > poster) suggested would be faster by far than forcing the > database to generate and sort GUIDS for every image every > time you want an image. > > It's really the old argument of "where" - do you do this in > CF or in the database. All the solutions presented will work > - but some work better depending on how often you use them > and how much you can cache. > > I was under the assumption that the album application would > be making use of the query information quite a bit. It would > probably be on hand cached some place. If that's the case > it's silly to make a round trip to the database to fetch > random record when you have the data already. > > But if the data's not be used elsewhere on the page or is not > cached and you're really only doing the query for a single > random image then your solution makes more sense. > > Jim Davis > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:219564 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

