Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Caching the results of db query?  (Read 7332 times)
Westside
Jr. Member
**
Posts: 12


View Profile Email
« on: December 29, 2008, 03:22:22 »

Hi,

How can I cache the results of a query.  I am generating a list of states (Alabama, Alaska, Arkansas, etc, etc) for various combo boxes in my application.  I want to get a list of the states once on startup, but have a way for the views that need the combobox to all look at once location for the data provider. 

How and where would I do this? As of now I have this, but it doesn't cache the results which is what I'd like

----
StatesCommand.as

var geographyProxy:GeographyProxy = facade.retrieveProxy( GeographyProxy.NAME ) as GeographyProxy;
geographyProxy.getStates();

GeographyProxy.as

public function getStates():void {
  remoteDelegate.getStates();
}

public function result( event:Object ):void      {   
    switch ( event.token.message.operation )   {
   case "getStates":
   var ac_result:ArrayCollection = event.result as ArrayCollection;
   var obj:Object = new Object();
             obj.state_code = '';
   obj.state_name = 'Choose a State';
   ac_result.addItemAt(obj, 0);
   sendNotification( STATES_LOADED, ac_result );
   break;
----

I am unsure how I can cache this as well as is this even the right way to setup my command and my proxy.  It also leads to a more frustrating problem that when this notification "STATES_LOADED" is distributed, some of the view components that need to hear it are not created yet which results in me having to make another db call for the same data when one of the other views doesn't exist.

Hope my post makes sense.

-Westside


« Last Edit: December 29, 2008, 03:39:28 by Westside » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: December 29, 2008, 05:42:30 »

This is wierd. I thought I answered this question the other day.

Anwyay first of all, I'd use an Enum for populating comboboxes with states. See the Enums in the employee admin demo for an idea of how this works.

If it has to be loaded data, then have your proxy be aware if it has already got the data.

Rather than send a notification with a reference to the data in the ResultEvent, set the proxy's data property to the result, expose a typed getter and send a reference to that in a STATES_DATA notification when the data comes back.
Have mediators interact async with the proxy by retrieving it, calling a 'fetchStates' method. That method then simply checks if the data property is null if so it makes the call, otherwise it immediately sends the STATES_DATA note. The inerested mediators take the data and populate their combos.

-=Cliff>
Logged
Pages: [1]
Print