Sunday, December 25, 2011

Using AppFabric


Client App Config:

<configSections>
    <!-- required to read the <dataCacheClient> element -->
    <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>
    <transportProperties maxBufferPoolSize="7" maxBufferSize="200000000"/>


    <!-- (optional) specify local cache
      <localCache
         isEnabled="true"
         sync="TimeoutBased"
         objectCount="100000"
         ttlValue="300" /> -->

    <!--(optional) specify cache notifications poll interval
      <clientNotification pollInterval="300" /> -->

    <hosts>
      <host name="10.32.68.136" cachePort="22233"/>
      <!--<host
         name="CacheServer2"
         cachePort="22233"/>-->
    </hosts>
  </dataCacheClient>
Client Code No Config:
           DataCacheFactoryConfiguration cfg= new DataCacheFactoryConfiguration();
            cfg.Servers= new DataCacheServerEndpoint[]
            {
                new DataCacheServerEndpoint("10.32.68.136",22233)//jqdappfabric.dev.gmo.tld",22233)
            };
            Microsoft.ApplicationServer.Caching.DataCacheFactory f = new DataCacheFactory(cfg);
            Console.WriteLine("Factory Created");
            DataCache c=f.GetDefaultCache();
            Console.WriteLine("Cache Connected");
            Console.WriteLine("Put into Cache");
            c.Put("k1","v1");
            Console.WriteLine("Get From Cache");
            Console.WriteLine(c.Get("k1"));
Client Code with Config:
          DataCacheFactory cf = new DataCacheFactory();
            DataCache cache = cf.GetDefaultCache();
            cache.Put("AllEntityHierarchy", list);
            object obj = cache.Get("AllEntityHierarchy");
NOTE: if Visual Studio 2010 Intelle-trace shows "No DNS entry" then use Hosts file.
   

Some usefull PowShellCommand:
 
 import/export-CacheClusterConfig: shows/set user permission.
 start/stop-cachecluster
 grant/invoke-CacheAllowedClientAccount

No comments: