Description

Enable, disable or toggle the cleanup of the FAST claims cache. 

When enabled, the cache will be cleaned out every 30 seconds

Disabling the cache cleanup is useful in development settings so that queries can be sent directly to the QR server.

This script does two things:

  1. Edits the components\sam\worker\user_config.xml file to set the AllowNonCleanUpClaimsCacheForTestingOnly attribute
  2. Restarts the samworker process

Both are easy to do by hand, but using this script will reduce chance of typos in editing the XML or forgetting to restart the samworker process.

This script also illustrates manipulating XML via PowerShell.

Usage

# Enable cleanup
.\Set-FASTSecurityClaimsCacheCleanup.ps1 -enable
# Disable cleanup
.\Set-FASTSecurityClaimsCacheCleanup.ps1 -disable
# Toggle current setting
.\Set-FASTSecurityClaimsCacheCleanup.ps1 -toggle

 

Script

 

PowerShell
Edit|Remove
<# 
.Synopsis 
  Enable, disable or toggle the cleanup of claims cache.   
 
  When enabled, the cache will be cleaned out every 30 seconds 
 
  Disabling the cache cleanup is useful in development settings 
  so that queries can be sent directly to the QR server 
.Parameter Enable 
  Enable cache cleanup.  This should always be the case in production 
.Parameter Disable 
  Disable cache cleanup.  Cache will not be cleaned every 30 seconds 
.Parameter Toggle 
  Toggle the current setting 
.LINK  
    http://gallery.technet.microsoft.com/ScriptCenter  
.NOTES  
    File Name : Set-FASTSecurityClaimsCacheCleanup.ps1  
    Author    : Matthew King  
#> 
 
param( 
  [Parameter(Mandatory=$true, ParameterSetName="Enabled")] 
  [switch]$Enable, 
  [Parameter(Mandatory=$true, ParameterSetName="Disabled")] 
  [switch]$Disable, 
  [Parameter(Mandatory=$true, ParameterSetName="Toggled")] 
  [switch]$Toggle 
) 
 
$userConfigFile = $env:FASTSEARCH + "components\sam\worker\user_config.xml" 
if (-not (Test-Path $userConfigFile)) { 
    Write-Error "Cannot find $userConfigFile" 
    exit 
} 
[xml] $xml = gc $userConfigFile 
$opt = $xml.configuration.unity.containers.container.instances.add | Where-Object { $_.name -eq "AllowNonCleanUpClaimsCacheForTestingOnly" } 
if (-not $opt) { 
    Write-Error "Cannot find element for AllowNonCleanUpClaimsCacheForTestingOnly" 
    exit 
} 
$newValue = "false" 
 
# NB  The actual parameter is a negative, but for making the cmdlet easier to use we've switched it around 
 
if ($Enable) { 
    $newValue = "false" 
} 
elseif ($Disable) { 
    $newValue = "true" 
} 
else { 
    if ($opt.value -eq "true") { 
        $newValue = "false" 
    } 
    else { 
        $newValue = "true" 
    } 
} 
$opt.value = $newValue 
 
Write-Host "Setting AllowNonCleanUpClaimsCacheForTestingOnly to $newValue" 
$xml.save($userConfigFile) 
 
nctrl restart samworker