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] `
[-ReplicationStrategy] -Size `
[-Topology] [-Credentials] `
[-InMemoryStoreType] [-UseExistingIndex] `
Important
If all ports in the configured 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 the required management port to the same cache in ports.xml. For details about management ports, see Cache Server Ports.
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 port number 7800.
New-Cache -Name defaultCache -Server 20.200.20.11 `
-Size 1024 -Topology Replicated `
-ClusterPort 7800
- 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 7800.
New-Cache -Name defaultCache -Server 20.200.20.11 `
-Size 1024 -Topology Partitioned `
-EvictionPolicy priority -DefaultPriority high `
-EvictionRatio 10 -CleanupInterval 20 `
-ClusterPort 7800
- 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 7800.
New-Cache -Name defaultCache -Server "20.200.20.11,20.200.20.12" `
-Size 1024 -Topology Replicated `
-ClusterPort 7800
- 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 7800.
New-Cache -Name defaultCache -Server 20.200.20.11 `
-Size 1024 -InMemoryStoreType PubSubMessaging `
-Topology Partitioned
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. | 7800 |
-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. | 9800 |
-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. | - |
-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 |