DVL Software Limited
[ About | Services | Products | Search | Feedback | Support ]

PowerBuilder Tips

Caching data and refreshing

Back to the Tips

If you're not caching your data, perhaps you might want to look at the n_cst_dwcache server from PFC.  The basic objective of a cache is to reduce database access and network traffic.  But there are some traps which you should be aware of.

Drop down datawindows

One such trap is drop down datawindows which use the cache.  Suppose you have a datawindow which contains a dddw.  You use GetDatawindowChild to populate the dddw with the data from the cache.  For our example, let's assume that the dddw displays ProductName.  In the maintenance screen, the user changes the name of the product and saves the results.  The cache contains the refreshed and correct name.  However, the dddw will not display properly.  It will contain the correct data, as shares with the cache.  But the screen needs to be repainted so the user sees the new name and not the old name.  The function of_RefreshSheets accomplishes this repaint.  We've added this function to n_cst_appmanager, but it could be placed on just about any other object.

In some circumstances, the cached data needs to be refreshed because the database has been modified directly.  In this case, see n_cst_dwcache::of_Refresh().


Purpose:	this is a fudge to fix up cache refresh.
		when a cache is refreshed, we must repaint all datawindows.
		this is the easy way to do this.

Parameters:	nil

Results:	1


w_frame	lw_Frame
w_sheet	lw_Sheet

lw_Frame = gnv_App.of_GetFrame()

lw_Sheet = lw_Frame.GetFirstSheet()
if IsValid(lw_Sheet) then
        // this will repaint any dddw etc.
        lw_Sheet = lw_Frame.GetNextSheet(lw_Sheet)
    LOOP UNTIL NOT IsValid(lw_Sheet)
end if

return 1

Table maintenance

Another issue with caching is table maintenance.  If you link your datawindow with the cache and allow the users to modify that data, what happens if they decide not to save any changes?  Not very nice.

So an option is not to share your table maintenance with the cache.  Instead, load your data directly from the database.  Then, after every save, refresh you cache.   Here's what we do:

// make sure that the cached version is refreshed appropriately.

// make sure the sheets are displaying the correct data

Another option, which I've thought about, but haven't tried, is to load your table maintenance from cache with a RowsCopy.  That would eliminate that database transfer if the data had already been loaded.

Back to the Tips

[ About | Services | Products | Search | Feedback | Support ]

This page last updated: Wednesday, 23 February 2000
Copyright 1997, 1998, 1999, 2000 DVL Software Limited.  All rights reserved.