1: using Microsoft.ApplicationServer.Caching;
 2: using System.Collections.Generic;
 3:  
 4: public class CacheUtil
 5: {
 6:   private static DataCacheFactory _factory = null;
 7:   private static DataCache _cache = null;
 8:  
 9:   public static DataCache GetCache()
 10:   {
 11:       if (_cache != null)
 12:           return _cache;
 13:  
 14:       //Define Array for 1 Cache Host
 15:       List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1);
 16:  
 17:       //Specify Cache Host Details 
 18:       // Parameter 1 = host name
 19:       // Parameter 2 = cache port number
 20:       servers.Add(new DataCacheServerEndpoint("mymachine", 22233));
 21:  
 22:       //Create cache configuration
 23:       DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
 24:        
 25:       //Set the cache host(s)
 26:       configuration.Servers = servers;
 27:        
 28:       //Set default properties for local cache (local cache disabled)
 29:       configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();
 30:  
 31:       //Disable tracing to avoid informational/verbose messages on the web page
 32:       DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);
 33:  
 34:       //Pass configuration settings to cacheFactory constructor
 35:       _factory = new DataCacheFactory(configuration);
 36:  
 37:       //Get reference to named cache called "default"
 38:       _cache = _factory.GetCache("default");
 39:        
 40:     return _cache;
 41:   }
 42: }