Clear-Cache
The Clear-Cache PowerShell cmdlet removes all cached items from a specified NCache cache instance. It allows safe removal of cache data with confirmation prompts, forceful execution when required, or selectively clearing of web-related content. This cmdlet is commonly used for cache maintenance, clearing stale or corrupted data, and resetting cache state during development, testing, or operational troubleshooting in distributed caching environments. It enables users to perform the following:
- Clear cache and asks before clearing cache.
- Clear cache forcefully.
- Clear the web content only.
Note
This feature is also available in the NCache Open Source edition, please keep in mind that NCache Open Source has different parameters in some cmdlet instances.
Clear-Cache -Name [-Server] [-Force] `
[-ClearJSS] [-NoLogo] `
[-LoadBalancerEnabled] [-TlsCertPath] `
[-TlsCertPassword] [-Credentials]
Examples
- This command clears the defaultCache after confirming whether the user wants to proceed.
Clear-Cache -Name defaultCache
- This command forcefully clears the cache and does not confirm with the user before clearing the cache.
Clear-Cache -Name defaultCache -Force
- This command clears JavaScript or CSS content from the cache.
Clear-Cache -Name defaultCache -ClearJSS
- This command clears the defaultCache on the server 20.200.20.11.
Clear-Cache -Name defaultCache -Server 20.200.20.11
- This command clears the defaultCache using the specified DNS, David-Watson.
Clear-Cache -Name defaultCache -Server David-Watson
- This command clears the defaultCache using the specified load-balanced server 20.200.20.11.
Clear-Cache -Name defaultCache -LoadBalancerEnabled `
-Server 20.200.20.11
- This command clears all items from defaultCache on the specified server with mutual TLS (mTLS) enabled. It runs from a machine where NCache is not installed and uses
C:\certs\client.pemto authenticate the machine running the cmdlet. The-TlsCertPasswordparameter decrypts the certificate’s password-protected private key. Omit this parameter if the private key is not encrypted.
Clear-Cache -Name defaultCache -Server 20.200.20.11 `
-TlsCertPath "C:\certs\client.pem" -TlsCertPassword "clientKeyPassword"
- This command clears the defaultCache after confirming whether the user wants to proceed using security credentials.
Clear-Cache -Name defaultCache -Credentials(Get-Credential john_smith)
Properties
Note
The parameters with asterisk (*) on their names are the required parameters and the rest are optional.
| Parameters | Data Types | Description | Default Value |
|---|---|---|---|
-Name* |
<String> |
Specifies the name of the cache which needs to be cleared. NOTE: The cache must already exist on the source server. |
- |
-Force |
<SwitchParameter> |
Providing this parameter cleans the cache forcefully, whereas in normal situations the user is asked before clearing the cache. | - |
-ClearJSS |
<SwitchParameter> |
Clears only the JavaScript and CSS files from the cache. NOTE: This option is not available in NCache Open Source. |
False |
-TlsCertPath |
<string> |
Path to the client PEM certificate used to authenticate the machine running the NCache PowerShell cmdlet when connecting to an NCache server with mutual TLS (mTLS) enabled. The PEM file must contain the private key, leaf certificate, and any intermediate certificates. You can generate a certificate using New-NCacheTlsCertificate. This parameter is required when running the PowerShell module from a machine where NCache is not installed and the server requires mTLS. On a machine with an NCache server installation, the node's own certificate is used automatically. Relative paths are resolved against the current PowerShell location, and the file must exist. To configure the certificate presented by the server, use -CustomCertificatePath. |
- |
-TlsCertPassword |
<string> |
Password used to load the encrypted private key in the PEM file specified by -TlsCertPath. Required only when the private key is password-protected. Not needed for an unencrypted private key. The password is used only to load the client certificate for the current command's connections. It is not saved in the NCache server configuration. |
- |
-NoLogo |
<SwitchParameter> |
Suppresses display of the logo banner. | False |
-Credentials |
<pscredential> |
Specifies the user credentials required to authorize access for the specified operation. These credentials should belong to a user with the appropriate permissions at the node. | - |
-Server |
<String> |
Specifies a server name where the NCache Service is running and a cache with the specified cache-name is registered. | IP of local machine |