New-Cache
The New-Cache cmdlet in PowerShell is used to create a new cache on designated server nodes. A new cache can be created by user-specified configurations in the configuration file placed on the path provided by the user if the user doesn't want to use the default configurations. It supports the creation of Local, Mirrored, Replicated, and Partitioned topologies. Moreover, it enables the setup of storage types such as Distributed Cache, Pub/Sub Messaging stores through cmdlets.
You can create a cache with the following topologies using this PowerShell cmdlet:
LocalReplicatedPartitionedPartitionReplica
Moreover, you also have to specify the InMemoryStoreType for these topologies as part of this PowerShell cmdlet. They are as follows:
DistributedCachePubSubMessaging
Note
It is recommended that you use JSON serialization if you are using ASP.NET 5.0 and above. For more details, click here.
New-Cache -Name [-Server] `
[-CleanupInterval] [-ClusterPort] `
[-DefaultPriority] [-EvictionPolicy] `
[-EvictionRatio] [-Inproc] `
[-SerializationFormat] [-NoLogo] `
[-Path] [-Port] `
[-TlsCertPath] [-TlsCertPassword] `
[-ReplicationStrategy] -Size `
[-Topology] [-Credentials] `
[-InMemoryStoreType] [-UseExistingIndex] `
Warning
If all ports in the configured CacheHost management port range are occupied, cache creation fails and NCache displays an error indicating that a custom management port is required. The NCache Service remains responsive. In this case, manually add the cache configuration to config.ncconf and assign a management port to the same cache in CacheHostPorts.xml located at %NCHOME%\bin\service. The cache must be present in both files.
Examples
- This command creates a new local cache named defaultCache on server 20.200.20.11 with size 1024 MB and uses local topology since no topology is specified.
New-Cache -Name defaultCache -Server 20.200.20.11 -Size 1024 -SerializationFormat JSON
- This command creates a new local cache named defaultCache on server 20.200.20.11 having the size of 1024 MB, with the configuration that exists on the specified path.
New-Cache -Name defaultCache -Server 20.200.20.11 -Path C:\config.xml
- This command creates a new distributed cache named defaultCache on server 20.200.20.11, having size 1024 MB with topology set to Replicated, and occupying the cluster port number 9881.
New-Cache -Name defaultCache -Server 20.200.20.11 `
-Size 1024 -Topology Replicated `
-ClusterPort 9881
- This command creates a new distributed cache named defaultCache on server 20.200.20.11 having the size of 1024 MB, topology as Partitioned, eviction policy set as priority based, default priority set as high, as well as eviction ratio set as 10%. The cleanup interval of the cache will be 20 seconds and port 9881.
New-Cache -Name defaultCache -Server 20.200.20.11 `
-Size 1024 -Topology Partitioned `
-EvictionPolicy priority -DefaultPriority high `
-EvictionRatio 10 -CleanupInterval 20 `
-ClusterPort 9881
- This command creates a new distributed cache named defaultCache on servers 20.200.20.11 and 20.200.20.12 having size 1024 MB, topology replicated, and occupying the port 9881.
New-Cache -Name defaultCache -Server "20.200.20.11,20.200.20.12" `
-Size 1024 -Topology Replicated `
-ClusterPort 9881
- This command creates a new distributed cache named defaultCache with store type
PubSubMessagingon server 20.200.20.11 having size 1024 MB with partitioned topology and occupying the port 9881.
New-Cache -Name defaultCache -Server 20.200.20.11 `
-Size 1024 -InMemoryStoreType PubSubMessaging `
-Topology Partitioned
- This command creates defaultCache with a size of 1024 MB on the specified server with mutual TLS (mTLS) enabled. It runs from a machine where NCache is not installed and uses C:\certs\client.pem to authenticate the machine running the cmdlet. The -TlsCertPassword parameter decrypts the certificate’s password-protected private key. Omit this parameter if the private key is not encrypted.
New-Cache -Name defaultCache -Server 20.200.20.11 `
-Size 1024 -TlsCertPath "C:\certs\client.pem" `
-TlsCertPassword "clientKeyPassword"
Note
If -Credentials are specified, NCache stores the provided credentials in the service configuration file.
- This command creates a new local cache named defaultCache on server 20.200.20.11 with size 1024 MB using security credentials.
New-Cache -Name defaultCache -Server 20.200.20.11 `
-Size 1024 -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 clustered cache with which the new client cache will be registered. | - |
-Server |
<String> |
Specifies a server name where the NCache Service is running and a cache with the specified cache-name is registered, and the NCache server names for cache configuration, separated by commas (e.g., "20.200.20.11, 20.200.20.12"). | IP of local machine |
-CleanupInterval |
<Integer> |
Specifies the time interval in seconds after which cache cleanup is called and all the expired items are cleared from the cache. | 15 seconds |
-ClusterPort |
<Integer> |
Specifies the port of the server, at which server listens. | 9881 |
-DefaultPriority |
<String> |
If the eviction policy opted by the user is Priority based; this parameter specifies the default priority. Possible values are: - High - Above Normal - Normal - Below Normal - Low |
Normal |
-EvictionPolicy |
<String> |
Specifies the eviction policy for cache items. Cached items will be cleared from the cache according to the specified policy if the cache reaches its limit. Possible values are - Priority Based - LFU - LRU NOTE: LRU and LFU are not available in NCache Open Source. |
LRU |
-EvictionRatio |
<Decimal> |
Specifies the eviction ratio (Percentage) for cache items. Cached items will be cleared from the cache according to the specified ratio if the cache reaches its limit. | 5% |
-Inproc |
<SwitchParameter> |
Specifies the Isolation level for local cache. | False |
-SerializationFormat |
<SwitchParameter> |
Specifies the serialization format of the objects stored in the cache. Possible values are - Binary - JSON |
Binary for DistributedCache and PubSubMessaging cache. |
-NoLogo |
<SwitchParameter> |
Suppresses display of the logo banner. | False |
-Path |
<String> |
Specifies the path of the configuration file if the user doesn’t want to use the default configurations. | - |
-Port |
<Integer> |
Specifies the server port where the NCache Service is listening. | 9803 |
-ReplicationStrategy |
<String> |
If the topology chosen by the user is Partitioned Replica; this parameter specifies the replication strategy. The possible values are - Async - Sync |
Async |
-Size* |
<Long> |
Specifies the size of the cache that is to be newly created. | 1024 (For Local Cache) |
-Topology |
<String> |
For topology other than local you have to give topology and cluster port. Specifies the topology in case of clustered cache. Possible topologies are - Mirror- Replicated- Partitioned- PartitionReplica NOTE: PartitionReplica is not available in NCache Open Source. |
Local |
-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. | - |
-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. |
- |
-InMemoryStoreType |
<String> |
Specifies the purpose for which this cache will be used. The possible values are: - DistributedCache - PubSubMessaging |
DistributedCache |
-UseExistingIndex |
<SwitchParameter> |
Specifies whether cache should use an existing index or create a new one. | False |