New-Cache - PowerShell Cmdlet
This PowerShell Cmdlet enables the user to create a new cache on one or more server nodes. A new cache can be created by user-specified configurations in a config file placed on the path provided by the user if the user doesn't want to use the default configurations.
You can create a cache with the following topologies using this PowerShell Cmdlet:
Local
Mirror
Replicated
Partitioned
PartitionReplica
(NCache Enterprise only)
Moreover, you also have to specify the InMemoryStoreType
for these topologies as part of this PowerShell Cmdlet. They are as follows:
DistributedCache
DistributedCacheWithPersistence
(Only forLocal
,PartitionReplica
, andPartitioned
topologies)PubSubMessaging
DistributedLuceneWithPersistence
(Only forLocal
,PartitionReplica
, andPartitioned
topologies)
Note
This feature is only available in NCache Enterprise and Professional.
Note
It is recommended that you use JSON serialization if you are using ASP.NET 5.0 and above. For more details click here. Also, the DistributedCacheWithPersistence
and DistributedLuceneWithPersistence
in-memory store types only support JSON serialization.
New-Cache [-Name] [-Server] [-CleanupInterval] [-ClusterPort] [-DefaultPriority] [-EvictionPolicy] [-EvictionRatio] [-Inproc] [-SerializationFormat] [-NoLogo ] [-Path] [-Port] [-ReplicationStrategy] [-Size] -Topology [-Credentials] [-InMemoryStoreType] [-UseExistingIndex] [-LuceneIndexPath] [-PersistenceStoreName] [-NewPersistenceStore] [-PersistenceStoreConnectionString]
Note
If you provide a path to your config.ncconf file through the Path
parameter in your command, then InMemoryStoreType
parameter can not be used. If it is used, you will be prompted with an error message.
Examples of New-Cache - PowerShell Cmdlet
- This command creates a new cache named demoCache on server 20.200.20.11 with size 1024 MB and uses local topology since no topology is specified.
New-Cache -Name demoCache -Server 20.200.20.11 -Size 1024
- This command creates a new cache named demoCache on server 20.200.20.11 having the size of 1024 MB, with the configuration that exists on the specified path.
New-Cache -Name demoCache -Server 20.200.20.11 –Path C:\config.xml
- This command creates a new cache named demoCache on server 20.200.20.11, having size 1024 MB and topology set as Replicated and occupying the port number 8701.
New-Cache -Name demoCache -Server 20.200.20.11 -Size 1024 –Topology Replicated –ClusterPort 8701
- This command creates a new cache named demoCache on server 20.200.20.11 having the size of 1024 MB, topology as Partitioned, eviction policy set as priority based and priority set as high as well as eviction ratio set as 10%. The cleanup interval of the cache will be 20 seconds.
New-Cache -Name demoCache -Server 20.200.20.11 -Size 1024 –Topology Partitioned –EvictionPolicy priority –DefaultPriority high –EvictionRatio 10 –CleanupInterval 20 -ClusterPort 8701
- This command creates a new distributed cache named demoCache on servers 20.200.20.11 and 20.200.20.12 having size 1024 MB, topology replicated and occupying the port 8701 for simple case.
New-Cache -Name demoCache -Server "20.200.20.11,20.200.20.12" -Size 1024 -Topology Replicated -ClusterPort 8701
- This command creates a new Distributed Cache named demoCache with store type of PubSubMessaging on server 20.200.20.11 having size 1024 MB with partitioned topology and occupying the port 8701 for simple case.
New-Cache -Name demoCache -Server "20.200.20.11" -Size 1024 -InMemoryStoreType PubSubMessaging -Topology Partitioned
- This command creates a new Distributed Lucene Cache named LuceneCache of store type DistributedLuceneWithPersistence on servers 20.200.20.11 and 20.200.20.12 having size 1024 MB with replication enabled. Lucene index is created at C:\LuceneIndexes\LuceneCache on all server nodes.
New-Cache -Name LuceneCache -Server "20.200.20.11,20.200.20.12" -Size 1024 -InMemoryStoreType DistributedLuceneWithPersistence -LuceneIndexPath "C:\LuceneIndexes" -Topology PartitionReplica
- This command creates a new Distributed Lucene Cache named LuceneCache of store type DistributedLuceneWithPersistence on servers 20.200.20.11 and 20.200.20.12. Since we are using
UseExistingIndex
flag, indices will be loaded from the default location of indices for current cache which is C:\ProgramData\ncache\lucene-index\LuceneCache, provided we have a valid module map at the specified location on all server nodes. Valid module map means same cache name, same topology, and same participating nodes as the original cache, which was used to generate those indices.
New-Cache -Name LuceneCache -Server "20.200.20.11,20.200.20.12" -Size 1024 -InMemoryStoreType DistributedLuceneWithPersistence -UseExistingIndex -Topology PartitionReplica
- This command creates a new Distributed cache with persistence named PersistenceCache of store type DistributedCacheWithPersistence on servers 20.200.20.11 and 20.200.20.12 having size 1024 MB with replication enabled. New persistence store named persistence_store is created at \\Fileserver\stores\store1 on all server nodes.
New-Cache -Name PersistenceCache -Server "20.200.20.11,20.200.20.12" -Size 1024 -InMemoryStoreType DistributedCacheWithPersistence -PersistenceStoreName "persistence_store" -NewPersistenceStore -PersistenceStoreConnectionString "\\Fileserver\stores\store1;domain_name\user_name;password" -Topology PartitionReplica
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 new cache that is to be registered. | - |
-Server |
<String> |
Specifies the NCache server names/IPs where Cache should be configured, separated by commas, e.g, 20.200.20.11, 20.200.20.12. | 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. | - |
-DefaultPriority |
<String> |
If the eviction policy opted by the user is Priority based; this parameter specifies the default priority. Possible values are |
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 NOTE: LRU and LFU are only available in Enterprise edition. |
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 |
<SwitchParamter> |
Specifies the Isolation level for local cache. | False |
-SerializationFormat |
<SwitchParamter> |
Specifies the serialization format of the objects stored in the cache. Possible values are |
Binary for DistributedCache and PubSubMessaging cache. JSON for DistributedCacheWithPersistence and DistributedLuceneWithPersistence 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 NCache server is listening. | 8250 |
-ReplicationStrategy |
<String> |
If the topology chosen by the user is Partitioned Replica; this parameter specifies the replication strategy. The possible values are |
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 only available in Enterprise edition. |
Local |
Credentials |
<pscredential> |
Specifies the user credentials required to authorize access for the specified operation. These credentials should belong to a user who has appropriate permissions at the node. | - |
-InMemoryStoreType |
<String> |
Specifies the purpose for which this cache will be used. The possible values are: DistributedCache DistributedCacheWithPersistence PubSubMessaging DistributedLuceneWithPersistence |
DistributedCache |
-UseExistingIndex |
<SwitchParameter> |
Specifies whether cache should use an existing index or create a new one. | False |
-LuceneIndexPath |
<String> |
Specifies the path where lucene indexes will be stored. This parameter is required if the store type for this cache is DistributedLuceneWithPersistence . |
- |
-PersistenceStoreName |
<String> |
Specifies the persistence store name. This parameter is required if the store type for this cache is DistributedCacheWithPersistence . |
- |
-NewPersistenceStore |
<SwitchParameter> |
Specifies that a new store be created for this cache. | True |
-PersistenceStoreConnectionString |
<String> |
Specifies a valid connection string for persistence store. This parameter is required if the store type for this cache is Distributed Cache With Persistence . |
- |