How Would You Tackle This Scenario?

Posted By : todd sharp Posted At : November 28, 2006 5:36 PM Posted In: CFCs, Flex, ColdFusion

8

Subtitle: I'm a noob and I'm pretending like this is a theoretical example.

I'm going to borrow a page from the Jedimaster's playbook and present this scenario as a "puzzler" to the CF community. I know it will seem a little naive and noobish, but hell - a lot of my posts show that I'm noobish and well, I really don't care. I always say if you're not going up you're going down - so I always try to gain more knowledge and if it helps someone else out there along the way then cool.

So here's the scenario: In my last post I shared a UDF that I had written earlier today that I plan to use to help me efficiently page through query results using a Flex datagrid. Bruce Phillips commented that he thought it would be interesting to try and recreate this functionality within the Flex front end with Actionscript. I started to reply in the comments, but decided to turn the issue into a whole new post. While his logic is valid in that it avoids recurring calls to the component, that idea wouldn't quite work in my scenario. Why wouldn't it work you may ask, well that's the noobish part. Let me give a little background to my application (without spoiling too much since it's still 'top secret').

Essentially the Flex application will deal with a potentially large dataset (for those in the OO crowd you could call this the 'gateway'). Since the dataset can grow quite large I planned to cache the data to improve performance. To do so, I created a query in my components instance and planned to cache the query in the instance data when the component is init()'d (onApplicationStart). My Flex app will interact with the component via a proxy component which will return the base component from the application scope. So far, so good. Now I have a query that can be returned to the Flex front end (and paged via the UDF I created). Finally, here's the part I still don't feel comfortable with. My component will have the standard CRUD methods for interacting with the dataset - not DAO's per se (because I just ain't that cool yet), but rather simple methods to add/update/delete items. My thought is that when the standard add/update/delete happens I could simply use some utility functions to add/update/delete the query in the instance data (yeah, that's the part you can laugh at). Doing so will keep the instance data 'live' and keeping it in the instance will ensure that the data is available to all active sessions upon there next call to the component.

If you're still with me - thank you ;). So what are my alternatives? Obviously I could create a refresh method and call it on A/U/D - but it seems like that would defeat the benefits of caching (if the cache has to constantly be updated).

Comments (8)

Gus's Gravatar As usual, the answer is... it depends!

For one thing, it depends on what you mean by "a potentially large dataset". Is a large dataset 100 records, 1,000 records or 10,000,000 records? How much data is there in each record?

I would not store what I consider to be a large dataset in memory as most of that dataset will likely never be called. I like to deal with paging at the database level so I only return what is needed to the client ( in this case ColdFusion ).

Gus

todd sharp's Gravatar How large? Hard to say - no more than a few thousand probably (1000-2000).

Paging at the db level - good idea. Only pain would be coding (dev environment is access - prod will probably be MSSQL).

I guess paging at the db level would eliminate the need to cache the query - just A/U/D straight into the db and refresh by returning a new paged recordset.

Know of any good examples of db level paging? A coworker mentioned a MSSQL proc that he had today - maybe I should look into that.

Brian Rinaldi's Gravatar 1 to 2 thousand records isn't that much... I think your caching scheme sounds like a big solution to a small problem. As for paging in the database, it's easy in MySQL, but a pain in MSSQL because it doesn't support offset (though I hope they changed this in 2005, but I don't have any experience in that yet, so if you are talking 2005, you should look into offset support). You can do it in MSSQL 2000, but it requires a subquery which isn't ideal. Anyway, I would actually just say, refresh the query when it is updated...and save yourself the complication.

todd sharp's Gravatar I like that answer Brian :)

So you don't think 1-2k isn't going to kill the memory? What if I were talking 10-20k? What is the "limit" for memory based caching? As Gus says - it probably "depends" --- isn't this a fun world we live in as programmers?

Brian Rinaldi's Gravatar I guess if that was the case my question would be, what would you be doing creating an application that pages through 10,000 records? I mean how usable is that? How many records would any one user ever really page through? Perhaps there is a more usable way to retrieve these records that would better address this issue from the standpoint of how the user might actually access the data.

todd sharp's Gravatar That was really more of a hypothetical - in all reality I'd be lucky if the amount ever reaches a few hundred. I'm just curious as to how massive resultsets are handled by larger applications. For example - Google - how do they page through a million search results -- and like you said, why bother? I mean how many of us have really ever made it past page 5 or 6 in Google?

Rahul Dhaware's Gravatar can u give me a source code of paging which is implemented in flex data grid
.plz

Martijn Wessels's Gravatar You can use this example:
SELECT * FROM (
SELECT TOP 5 * FROM (
SELECT TOP 5 * FROM (
SELECT Top #tel * From Objecten Order by Objectnummer ASC
) AS a ORDER BY Objectnummer DESC
) AS b
) AS c ORDER BY Objectnummer ASC

From code:
For i As Integer = total mod step To total Step 5
thread = New System.Threading.Thread(AddressOf loadObjects)
thread.Start(#tel)
Next

Just an example, not useable like this