I’ve been trying to write a simple little Cmdlet to allow me to Set/Get/Remove cache items. The problem I have is that I cannot figure out how to connect to the local cache cluster.
I’ve tried adding in the usual app.config stuff, but that doesn’t seem to get picked up …
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere" />
</configSections>
<dataCacheClient>
<hosts>
<host name="localhost" cachePort="22233" />
</hosts>
</dataCacheClient>
</configuration>
I’d rather not have that config at all. So what I am really asking is what the equivalent C# code is for the following powershell…
Use-CacheCluster
From what I can gather Use-CacheCluster connect to the local cluster if no parameters are supplied
I’ve just done some spelunking into the AppFabric Powershell code with Reflector to see how it works under the covers. If you call
Use-CacheClusterwith no parameters e.g. for the local cluster, the code reads the connection string and provider name from the Registry keyHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\AppFabric\V1.0\Configuration. Unfortunately, it then uses those values to build a series of classes (ClusterConfigElement,CacheAdminandClusterHandler) which are all marked as internal, so you can’t use them to pick up the current cluster context (for want of a better word) that Powershell is working with.To make your Cmdlet work, then, I think you need to pass in a hostname (which would be one of the servers in your cluster, and perhaps you could default this to the local machine name) and a port number (which you could default to 22233), and use those values to build a
DataCacheServerEndpointto pass to yourDataCacheFactorye.g.