Start and Administer your Memory Cluster from PowerShell
After Installation & Setting up Cache, do as below to start using Cache.
1. Go to the Start Menu and type in Caching. You'll have an item called "Caching Administration Windows PowerShell."
2. Run it as Administrator.
3. Type "get-command *cache*" to see all the different commands available for cache management.
4. To Know all up & running - Type: Start-Cachecluster
HostName : CachePort Service Name Service Status Version Info
-------------------- ------------ -------------- ------------
HANSELMAN-W500:22233 AppFabricCachingService UP 1 [1,1][1,1]
5. Also Note, Installing Cache add two below library in Visual Studio.
· Microsoft.ApplicationServer.Caching.Core
· Microsoft.ApplicationServer.Caching..Client
6. Also Note - Whenever there is a memory upgrade/degrade of RAM on any of the servers where the App fabric cache is installed, by default, the cachesize should be allocated half of the installed physical memory i.e. if the RAM is increased from 2GB to 4GB, the following command should be run
Set-Cachehostconfig -hostname <HOSTNAME> -cacheport 22233 -cachesize 2048
7. To Restart the Cache Cluster - Use the command Restart-CacheCluster
8. After Complete Installation of App Fabric Cache, you can change the startup Type of the ‘AppFabric Caching Service’ from ‘Manual’ to ‘Automatic’ from Services.msc. This will ensure that the caching service will restart after server restart
Chopping Cache Memory:
App Fabric beauty lies due to its "Memory Chopping' capabilities. I.e. Memory caches can be chopped off into logical buckets (partitions) and a memory cluster can serve more than one application, if you wanted.
This can be done in the web.config or from code (however you like).
Here's a code example helper method where the sample does this manually.
This data could come from wherever you like, you just need to tell it a machine to talk to and the port number. It'll automatically connect to the Caches can also be partitioned.
using Microsoft.ApplicationServer.Caching;
using System.Collections.Generic;
public class CacheUtil
{
private static DataCacheFactory _factory = null;
private static DataCache _cache = null;
public static DataCache GetCache()
{
if (_cache != null)
return _cache;
//Define Array for 1 Cache Host
List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1);
//Specify Cache Host Details
// Parameter 1 = host name
// Parameter 2 = cache port number
servers.Add(new DataCacheServerEndpoint("mymachine", 22233));
//Create cache configuration
DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
//Set the cache host(s)
configuration.Servers = servers;
//Set default properties for local cache (local cache disabled)
configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();
//Disable tracing to avoid informational/verbose messages on the web page
DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);
//Pass configuration settings to cacheFactory constructor
_factory = new DataCacheFactory(configuration);
//Get reference to named cache called "default"
_cache = _factory.GetCache("default");
// Create Region
string region1 = "shoppingcart";
string region2 = "productcatalog";
_cache.CreateRegion(region1);
_cache.CreateRegion(region2);
return _cache;
}
}
Reference:
Please check the link below.
Thanks & Regards,
Arun Manglick,
Project Manager - Forecasting
Mobile: 9158041782| 9850901262| Desk Phone: +912040265348 | http://www.synechron.com
SYNECHRON -
- 4,000+ professionals globally.
- USA | Canada | UK | The Netherlands | UAE | India | Singapore | Hong Kong | Japan
No comments:
Post a Comment