新缓存 - PowerShell Cmdlet
此 PowerShell Cmdlet 使用户能够在一个或多个服务器节点上创建新的缓存。如果用户不想使用默认配置,则可以通过放置在用户提供的路径上的配置文件中的用户指定的配置来创建新的缓存。
您可以使用此 PowerShell Cmdlet 创建具有以下拓扑的缓存:
Local
Mirror
Replicated
Partitioned
PartitionReplica
(NCache Enterprise 只有)
此外,您还必须指定 InMemoryStoreType
作为此 PowerShell Cmdlet 的一部分用于这些拓扑。它们如下:
DistributedCache
DistributedCacheWithPersistence
(仅适用于Local
,PartitionReplica
及Partitioned
拓扑)PubSubMessaging
DistributedLuceneWithPersistence
(仅适用于Local
,PartitionReplica
及Partitioned
拓扑)
备注
如果您使用的是 ASP.NET 5.0 及更高版本,建议您使用 JSON 序列化。 更多详情请点击 此处。 此外, DistributedCacheWithPersistence
和 DistributedLuceneWithPersistence
内存存储类型仅支持 JSON 序列化。
New-Cache [-Name] [-Server] [-CleanupInterval] [-ClusterPort] [-DefaultPriority] [-EvictionPolicy] [-EvictionRatio] [-Inproc] [-SerializationFormat] [-NoLogo ] [-Path] [-Port] [-ReplicationStrategy] [-Size] -Topology [-Credentials] [-InMemoryStoreType] [-UseExistingIndex] [-LuceneIndexPath] [-PersistenceStoreName] [-NewPersistenceStore] [-PersistenceStoreConnectionString]
备注
如果您提供通往您的 配置文件 通过文件 Path
命令中的参数,然后 InMemoryStoreType
参数不能使用。 如果使用它,您将收到一条错误消息提示。
New-Cache 示例 - PowerShell Cmdlet
- 此命令在服务器 20.200.20.11 上创建一个名为 demoCache 的新缓存,大小为 1024 MB,并使用本地拓扑,因为未指定拓扑。
New-Cache -Name demoCache -Server 20.200.20.11 -Size 1024
- 此命令在服务器 20.200.20.11 上创建一个名为 demoCache 的新缓存,大小为 1024 MB,并使用指定路径上存在的配置。
New-Cache -Name demoCache -Server 20.200.20.11 –Path C:\config.xml
- 该命令在服务器 20.200.20.11 上创建一个名为 demoCache 的新缓存,大小为 1024 MB,拓扑设置为 Replicated,占用端口号 8701。
New-Cache -Name demoCache -Server 20.200.20.11 -Size 1024 –Topology Replicated –ClusterPort 8701
- 此命令在服务器 20.200.20.11 上创建一个名为 demoCache 的新缓存,大小为 1024 MB,拓扑为分区,逐出策略设置为基于优先级,优先级设置为高,逐出比率设置为 10%。 缓存的清理间隔为20秒。
New-Cache -Name demoCache -Server 20.200.20.11 -Size 1024 –Topology Partitioned –EvictionPolicy priority –DefaultPriority high –EvictionRatio 10 –CleanupInterval 20 -ClusterPort 8701
- 此命令在服务器 20.200.20.11 和 20.200.20.12 上创建一个名为 demoCache 的新分布式缓存,大小为 1024 MB,复制拓扑并占用端口 8701(对于简单情况)。
New-Cache -Name demoCache -Server "20.200.20.11,20.200.20.12" -Size 1024 -Topology Replicated -ClusterPort 8701
- 此命令在服务器 20.200.20.11 上创建一个名为 demoCache 的新分布式缓存,存储类型为 PubSubMessaging,大小为 1024 MB,具有分区拓扑,并在简单情况下占用端口 8701。
New-Cache -Name demoCache -Server "20.200.20.11" -Size 1024 -InMemoryStoreType PubSubMessaging -Topology Partitioned
- 此命令在服务器 20.200.20.11 和 20.200.20.12 上创建一个名为 LuceneCache 的新分布式 Lucene 缓存,存储类型为 DistributedLuceneWithPersistence,大小为 1024 MB,并启用了复制。 Lucene 索引创建于 C:\LuceneIndexes\LuceneCache 在所有服务器节点上。
New-Cache -Name LuceneCache -Server "20.200.20.11,20.200.20.12" -Size 1024 -InMemoryStoreType DistributedLuceneWithPersistence -LuceneIndexPath "C:\LuceneIndexes" -Topology PartitionReplica
- 此命令在服务器 20.200.20.11 和 20.200.20.12 上创建一个名为 LuceneCache 的新分布式 Lucene 缓存,其存储类型为 DistributedLuceneWithPersistence。 由于我们正在使用
UseExistingIndex
标志,索引将从当前缓存的默认索引位置加载,即 C:\ ProgramData \ncache\lucene-index\LuceneCache,前提是我们在所有服务器节点上的指定位置都有一个有效的模块映射。有效的模块映射意味着与用于生成这些索引的原始缓存具有相同的缓存名称、相同的拓扑和相同的参与节点。
New-Cache -Name LuceneCache -Server "20.200.20.11,20.200.20.12" -Size 1024 -InMemoryStoreType DistributedLuceneWithPersistence -UseExistingIndex -Topology PartitionReplica
- 此命令在大小为 20.200.20.11 MB 且启用复制的服务器 20.200.20.12 和 1024 上创建一个名为 PersistenceCache、存储类型为 DistributedCacheWithPersistence 的新的具有持久性的分布式缓存。 名为 persistence_store 的新持久性存储创建于 \\文件服务器\商店\商店1 在所有服务器节点上。
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
查看房源
备注
名称上带有星号 (*) 的参数为必填参数,其余为可选参数。
参数 | 数据类型 | 课程描述 | 默认值 |
---|---|---|---|
-Name* |
<String> |
指定要注册的新缓存的名称。 | - |
-Server |
<String> |
指定 NCache 应配置缓存的服务器名称/IP,以逗号分隔,例如 20.200.20.11, 20.200.20.12。 | 本地机器 |
-CleanupInterval |
<Integer> |
指定调用缓存清理并从缓存中清除所有过期项目的时间间隔(以秒为单位)。 | 15秒 |
-ClusterPort |
<Integer> |
指定服务器侦听的服务器端口。 | - |
-DefaultPriority |
<String> |
如果用户选择的驱逐策略是基于优先级的; 此参数指定默认优先级。 可能的值为 |
正常 |
-EvictionPolicy |
<String> |
指定缓存项的逐出策略。 如果缓存达到其限制,缓存项将根据指定的策略从缓存中清除。 可能的值为 注意: LRU 和 LFU 仅在企业版中可用。 |
LRU |
-EvictionRatio |
<Decimal> |
指定缓存项的逐出率(百分比)。 如果缓存达到其限制,缓存的项目将按照指定的比例从缓存中清除。 | 5% |
-Inproc |
<SwitchParamter> |
指定本地缓存的隔离级别。 | 假 |
-SerializationFormat |
<SwitchParamter> |
指定存储在缓存中的对象的序列化格式。 可能的值为 |
二进制 DistributedCache 和 PubSubMessaging 缓存。 JSON 用于 DistributedCacheWithPersistence 和 DistributedLuceneWithPersistence 缓存 |
-NoLogo |
<SwitchParameter> |
禁止显示标志横幅。 | 假 |
-Path |
<String> |
如果用户不想使用默认配置,则指定配置文件的路径。 | - |
-Port |
<Integer> |
指定服务器端口 NCache 服务器正在侦听。 | 8250 |
-ReplicationStrategy |
<String> |
如果用户选择的拓扑是Partitioned Replica; 此参数指定复制策略。 可能的值为 |
异步 |
-Size |
<Long> |
指定要新建的 Cache 的大小。 | 1024(用于本地缓存) |
-Topology |
<String> |
对于拓扑以外的 local 您必须提供拓扑和集群端口。 指定集群缓存的拓扑。 可能的拓扑是 Mirror Replicated Partitioned PartitionReplica 注意: PartitionReplica 仅在企业版中可用。 |
Local |
Credentials |
<pscredential> |
指定授权访问指定操作所需的用户凭据。 这些凭据应属于在节点上具有适当权限的用户。 | - |
-InMemoryStoreType |
<String> |
指定使用此缓存的目的。 可能的值是: DistributedCache DistributedCacheWithPersistence PubSubMessaging DistributedLuceneWithPersistence |
DistributedCache |
-UseExistingIndex |
<SwitchParameter> |
指定缓存应该使用现有索引还是创建新索引。 | 假 |
-LuceneIndexPath |
<String> |
指定 lucene 索引的存储路径。 如果此缓存的存储类型是,则需要此参数 DistributedLuceneWithPersistence . |
- |
-PersistenceStoreName |
<String> |
指定持久性存储名称。 如果此缓存的存储类型为 DistributedCacheWithPersistence . |
- |
-NewPersistenceStore |
<SwitchParameter> |
指定为此缓存创建一个新存储。 | 真 |
-PersistenceStoreConnectionString |
<String> |
指定持久性存储的有效连接字符串。 如果此缓存的存储类型是,则需要此参数 Distributed Cache With Persistence . |
- |