Share via


Managing Caches

Once your Microsoft AppFabric 1.1 for Windows Server cache cluster is running, the focus shifts to the management of individual caches on the cache cluster. This section provides examples of how to use Windows PowerShell commands to perform common cache management functions. For a comprehensive list of cache management commands, see Using Windows PowerShell with AppFabric Caching.

Create a New Cache

The following example uses the New-Cache command to create a new cache named Cache1. Default values are used for all cache configuration settings.

New-Cache Cache1

The following example creates a new cache named Cache2. This example sets the Secondaries parameter to 1, which enables High Availability for this cache. Note that this requires all cache hosts to be running the Enterprise or Datacenter editions of Windows Server. This example also enables notifications by setting the NotificationsEnabled parameter to "true". For more information about these AppFabric Caching features, see Caching Concepts.

New-Cache Cache2 -Secondaries 1 -NotificationsEnabled "true"

Note that cache names are typically case-sensitive. The exception to this rule is when your cache configuration store uses SQL Server with a database that uses a case-insensitive collation.

There is a limit of 128 named caches. If you require more than 128 caches, client applications could consider using regions. A client application can create a region with the CreateRegion method of the DataCache class. You can have multiple regions in a single cache, and cache keys that have the same names in different regions are still unique. This does affect application design. Therefore, it is important to communicate this cache limit with development teams.

List Caches and Regions

The Get-Cache command lists all of the caches on the cache cluster and their regions.

Get-Cache

On an active cache cluster, default regions are created by AppFabric. As the cache grows, the number of these default regions increases. Applications are also able to create their own regions. If you are only interested in viewing the cache names without the region information, you can set the MaxRegions parameter to 0. The following example demonstrates this technique.

Get-Cache -MaxRegions 0

You can also view cache information about a specific cache host. Although a single cache can be distributed across multiple hosts, the regions in that cache might differ between hosts. The following command shows all of the cache information for a cache host named CacheServer1 with a cache port of 22233. This example limits the MaxRegionsPerCache to 10.

Get-Cache -HostName CacheServer1 -CachePort 22233 -MaxRegionsPerCache 10

Although Get-Cache displays region information, you can also view region information with the Get-CacheRegion command. The following command displays 10 regions per cache host in the cluster.

Get-CacheRegion -MaxRegionsPerHost 10

Remove a Cache

The Remove-Cache command removes a cache from the cache cluster.

Remove-Cache Cache1

View the Cache Configuration Settings

To view the current settings for a cache, use the Get-CacheConfig command.

Get-CacheConfig Cache1

In the previous example, the Get-CacheConfig command displays the cache configuration settings for Cache1. Here is an example of the output from this command.

CacheName            : Cache1
TimeToLive           : 10 mins
CacheType            : Partitioned
Secondaries          : 0
IsExpirable          : True
EvictionType         : LRU
NotificationsEnabled : False

The following table provides more information about each of these settings.

Setting Description

CacheName

The name of the cache.

TimeToLive

The default time that items reside in the cache before expiring.

CacheType

The type of cache. This is always Partitioned.

Secondaries

A value of 1 indicates that the cache uses the high availability feature.

IsExpirable

Indicates whether objects in the cache can expire.

EvictionType

Specifies an eviction type of Least-Recently-Used (LRU) or None.

NotificationsEnabled

Indicates whether notifications are enabled for this cache.

For more information about these cache features, see Expiration and Eviction, High Availability, and Cache Notifications.

Change the Cache Configuration Settings

At times, you may want to change the configuration settings for an existing cache. There are two available processes:

  • Remove the cache with Remove-Cache command, and re-create the cache with the required settings with New-Cache command.

  • Use the Set-CacheConfig command.

For example, in the previous example, a developer decides to use cache notifications for the Cache1 cache. Although they change their code to use notifications, the application will fail if notifications are not enabled for the Cache1 cache. You can decide to remove and re-create the cache with the desired setting.

Remove-Cache Cache1

The previous example removes Cache1. You must wait several minutes while the cache is being deleted before recreating it. If you attempt to re-create the cache too soon, you will get a message that the deletion of the cache is in-progress. After this delay, you can re-create the cache, specifying that notifications are enabled.

New-Cache Cache1 -NotificationsEnabled True

When you use this method, you should look carefully at the configuration settings with the Get-CacheConfig command. You'll have to also specify any non-default settings for the recreated cache in addition to the setting that you want to change.

You can also use the Set-CacheConfig command. The benefit of this command is that it preserves the other settings and changes only the setting you specify. This command requires that you stop the cache cluster.

Stop-CacheCluster 
Set-CacheConfig Cache1 -NotificationsEnabled True 
Start-CacheCluster

With both of these techniques, all of the data in the cache will be removed and the cache will be unavailable for a short time. Consequently, these changes are best done during a maintenance window. If possible, applications should be designed to run when the cache is down for short periods of time. Also note that for some changes such as NotificationsEnabled, the client applications do not reflect the configuration changes automatically. Instead, these applications must create a new DataCacheFactory and call GetCache on the cache to reflect the changes to the cache configuration. A simple way to do this is to restart the client applications.

See Also

Concepts

Common Cache Cluster Management Tasks (Windows Server AppFabric Caching)

  2012-10-26