In PowerShell Provider, when do you update cache data?

I am writing a PowerShell provider in C #. The provider provides application domain objects through the drive interface. For instance:

my:\Users\ joe@blow.com my:\Customers\Marty 

This data ultimately comes from the database.

I was not able to find a great guide for when you should go to the database for data, and when you should cache it. I believe that PowerShell names methods many times, such as ItemExists and GetChildNames; often repeated for the same team. It is incorrect to access the database 5 or 6 times just because, for example, they press the Tab key to end automatically.

But at the same time, as a user on the command line, if I type Get-ChildItem ( dir ) and look at the list, then do something outside of PowerShell so that I know that the data is updated, taking another directory listing should expect to see some or changes to the database.

I feel that if I knew the correct term to describe my problem (in PowerShell), I could answer Google or find an existing duplicate question, but I'm stuck.

+6
source share
1 answer

This has very little to do with powershell and everything related to your data, and how important it is to update it. A simple caching scheme would be to use a temporary system in which, after N minutes, a request to your back level of data would pull out a new copy and reset the timer. It seems you already have an idea what your specific rules should be. I donโ€™t think that two consecutive "dir" commands should always lead to two pulls from the backup storage, but you think so about this system. So do it.

UPDATE

Perhaps a simple guideline might be that you should update your data only once after issuing a vendor command. The list of built-in commands that work with provider items consists of:

  • Clear item
  • Copy-item
  • Get-item
  • Invoke-item
  • Move-Item
  • New-item
  • Remove-Item
  • Rename-Item
  • Set-item

In addition, the list of built-in commands that work with the properties of a provider item consists of:

  • Clear-ItemProperty
  • Copy-ItemProperty
  • Get-ItemProperty
  • Move-ItemProperty
  • New-ItemProperty
  • Remove-ItemProperty
  • Rename-ItemProperty
  • Set-ItemProperty

And finally, for reading / writing content we use:

  • Add content
  • Clear content
  • Get-content
  • Set-content

Each of these commands has a corresponding method in NavigationCmdletProvider (for hierarchical data stores), and here you can update your data. When implementing the New / Move / Rename / Remove / Set / Clear methods and other data modification methods, you should use some optimistic concurrency methodology, since the provider instances in PowerShell are not single; at any time there can be one or more copies.

I wrote a provider that takes its implementation from a script, which might turn out to be a simpler prototype of things. See http://psprovider.codeplex.com/

Hope this helps.

+5
source

Source: https://habr.com/ru/post/894597/


All Articles