I am writing a PowerShell provider in C#. The provider exposes an applications domain objects through a drive-like interface. For example:
my:\Users\joe@blow.com
my:\Customers\Marty
This data ultimately comes from a database.
I have been unable to find any great guidance for when you should go to the database for data, and when you should cache it. I find that PowerShell calls methods like ItemExists and GetChildNames many times; often repeatedly for the same command. It is impractical to go to the database 5 or 6 times just because they hit Tab for auto-complete, for example.
But at the same time, as a user at the command prompt, if I type Get-ChildItem
(dir
) and see the list, then do something outside PowerShell so that I know the data is refreshed, taking another directory listing should expect to see any changes to the database.
I feel that if I knew the right term to describe my problem (in PowerShell parlance) I would be able to Google the answer or find an existing duplicate question, but I'm stuck.