Cache variable on IIS


I’m working on a dashboard that will be hosted on IIS and use scheduled endpoints to make API calls every few hours. The API calls are used to populate cache variables with the returned data. the scheduled endpoints live in the dashboard.ps1 file. The cache variables are referenced by a separate page on the dashboard.

When I run the site locally my page is able to utilize the variables and display their content. Once I move to IIS the page does not seem to be able to reference the variables. Everything that uses the cache variable will have no content. Testing the variables in design terminal I see that they still have data.

Is there anything additional I need to do with cache variables to make them work on IIS? As I understand it once they are defined they should be available across any endpoint.


The only thing I had to, in IIS, was to make sure that the Application Pool user had the needed access to query the data that is put in the variables (in my case data from a Database).
No additional changes was needed.

Since you confirm that the Data is in the Cache variable using the design terminal, it should be working.

I’ve had issues with the timing of the endpoint schedule, and the schedule of the refreshing of the components that display the data. maybe thats relevant?

it would be helpful if you could share the code in the schedule, and the code to display the info.

Thanks, PorreKaj. Here is one of the scheduled endpoints I am using:

$4hourSchedule = New-UDEndpointSchedule -Every 60 -Minute`
$2hourSchedule = New-UDEndpointSchedule -Every 30 -Minute

$fetchAutomateData = New-UDEndpoint -Schedule $4hourSchedule -Endpoint {
  $reportIds = ((Invoke-WebRequest -Headers @{ "api-token" = $automateAPIToken } -UseBasicParsing -Uri $automateURL/api/v0/compliance/reporting/nodes/search -Method POST -Body '{
    "filters": [
      {"values": ["azure-api"],"type": "environment" },
      {"values": ["jha-azure-benchmarks"],"type": "profiles" }
    "sort": "latest_report.end_time",
    "order": "DESC"
  }').content | Convertfrom-Json)

  $reports = New-Object System.Collections.ArrayList
  $Cache:reportscache = New-Object System.Collections.ArrayList
  $reportIds | ForEach-Object {
    $report = ((Invoke-WebRequest -Headers @{ "api-token" = $automateAPIToken } -Uri $automateURL/api/v0/compliance/reporting/reports/id/$_ -Method POST -UseBasicParsing).content | ConvertFrom-Json)
  $Cache:reportscache = $reports

Once I start the dashboard I can use the design terminal to see the $Cache:reportscache variable is populated. One of the areas I use the data is in an input section. I loop through the cache variable and create input fields off of it:

New-UDInput -Title 'Filters' -SubmitText 'Display Subscription(s)' -Id 'filters' -Content {
  New-UDInputField -Type 'select' -Name 'environment' -Placeholder 'Environment' -Values @('All','Production','Dev\Test','None')
  $groups = New-Object System.Collections.ArrayList
  $ | Where-Object type -eq '/providers/Microsoft.Management/managementGroups' | Sort-Object -Property displayName | ForEach-Object {
  New-UDInputField -Type 'select' -Name 'bu' -Placeholder 'Business Unit' -Values $groups
  $Cache:reportscache | Sort-Object -Property node_name | ForEach-Object {
    New-UDInputField -Type 'checkbox' -Name "$(($_.node_name).replace(' ','').replace('.','').replace('-',''))" -Placeholder $_.node_name

This loop creates no data off of the reportscache variable. I have also created another item that displays the count of items in reportscache and it shows 0 on IIS. When I run locally it correctly shows the number of items.

I’ve noticed similar behavior to this with IIS setup as well. Declaring a $Cache: var at the top of the page for instance, and it not being usable by commands executed with button clicks and such.

Eventually I created a scheduled endpoint to run regularly and re-declare the $Cache vars and that seems to be a work-around, but I don’t feel like this is a proper fix either.

I’m in a hurry, but with Quick look, it looks like the code to create the Checkboxes off the $Cache:reportscache, is in the -Content part on New-UDInput.

If i’m not mistaken, everything in -Content is build when the dashboard is made, and at that point the Cache variable is empty.
Is the page dynamic?

Thanks PorreKaj, that was exactly it! I nested by Input in an element endpoint and it’s now working. Thanks for your help!

:sunglasses: Glad I could help