Suppose you need to find an account name by its emal (via account prop):
The code then looks like this:
Code: Select all
function FindAccountByEmail( email )
var account;
foreach acctname in ListAccounts()
account = FindAccount( acctname );
if( account.getprop("email")==email )
return account;
endif
endforeach
return error{errortext:="No account with email "+email+" found.."};
endfunction
if you rewrite it to use caching, it will take NLog(n) (or whatever lookup POL dictionaries have; I expect them to be BTrees) which is considerably faster.
Code: Select all
function FindAccountByEmail( email )
var account;
if(not IsCacheHitDatafile( "acct_by_email", email ))
foreach acctname in ListAccounts()
account = FindAccount( acctname );
if( account.getprop("email")==email )
CacheInDatafile( "acct_by_email", email, acctname )
return FindAccount( GetLastCached() );
endif
endforeach
else
return FindAccount( GetLastCached() );
endif
return error{errortext:="No account with email "+email+" found.."};
endfucntion