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("192.168.1.31", 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"); return(_cache); }
public static DataCache GetCache() { if (_cache != null) { return(_cache); } if (string.IsNullOrEmpty(HostName)) { HostName = "adevweb019"; } CachePort = 22233; CacheName = "default"; List <DataCacheServerEndpoint> servers = new List <DataCacheServerEndpoint>(1); servers.Add(new DataCacheServerEndpoint(HostName, CachePort)); Configuration = new DataCacheFactoryConfiguration(); Configuration.SecurityProperties = CacheSecurity; Configuration.Servers = servers; Configuration.LocalCacheProperties = new DataCacheLocalCacheProperties(); DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); _factory = new DataCacheFactory(Configuration); _cache = _factory.GetCache(CacheName); return(_cache); }
private static DataCache GetCache() { if (dataCache != null) { return(dataCache); } Console.WriteLine(APPFABRIC_SERVER_HOSTNAME); Console.WriteLine(APPFABRIC_SERVER_PORT); var servers = new List <DataCacheServerEndpoint>(1) { new DataCacheServerEndpoint(APPFABRIC_SERVER_HOSTNAME, APPFABRIC_SERVER_PORT) }; var configuration = new DataCacheFactoryConfiguration { Servers = servers, LocalCacheProperties = new DataCacheLocalCacheProperties() }; DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); dataCacheFactory = new DataCacheFactory(configuration); dataCache = dataCacheFactory.GetCache(APPFABRIC_CACHENAME); return(dataCache); }
public DataCache ConstructCache() { ParseConfig(AppFabricConstants.DEFAULT_ServerAddress, AppFabricConstants.DEFAULT_Port); var dataCacheEndpoints = new List <DataCacheServerEndpoint>(); CacheConfiguration.ServerNodes.ForEach(e => dataCacheEndpoints.Add(new DataCacheServerEndpoint(e.IPAddressOrHostName, e.Port))); var factoryConfig = new DataCacheFactoryConfiguration(); factoryConfig.Servers = dataCacheEndpoints; var configMapper = new FactoryConfigConverter(Logger); configMapper.MapSettingsFromConfigToAppFabricSettings(CacheConfiguration, factoryConfig); IsLocalCacheEnabled = configMapper.IsLocalCacheEnabled; //SetSecuritySettings(config, factoryConfig); try { Logger.WriteInfoMessage("Constructing AppFabric Cache"); var factory = new DataCacheFactory(factoryConfig); DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Error); // Note: When setting up AppFabric. The configured cache needs to be created by the admin using the New-Cache powershell command string cacheName; // Prefer the new config mechanism over the explicit entry but still support it. So we // try and extract config from the ProviderSpecificValues first. if (CacheConfiguration.ProviderSpecificValues.ContainsKey(AppFabricConstants.CONFIG_CacheNameKey)) { cacheName = CacheConfiguration.ProviderSpecificValues[AppFabricConstants.CONFIG_CacheNameKey]; } else { cacheName = MainConfig.Default.DistributedCacheName; } Logger.WriteInfoMessage(string.Format("Appfabric Cache Name: [{0}]", cacheName)); DataCache cache = null; if (string.IsNullOrWhiteSpace(cacheName)) { cache = factory.GetDefaultCache(); } else { cache = factory.GetCache(cacheName); } Logger.WriteInfoMessage("AppFabric cache constructed."); return(cache); } catch (Exception ex) { Logger.WriteException(ex); throw; } }
public DistributedCacheManager() { EventLog.WriteEntry("Application", "AppFabric Constructor", EventLogEntryType.Information, 9111); DataCacheClientLogManager.ChangeLogLevel(TraceLevel.Off); _applicationSettingService = EngineContext.Current.Resolve <IApplicationSettingService>(); InitializeFactory(); _cacheClients = new ConcurrentDictionary <string, CacheClient>(); }
public AppFabricCacheProvider() { dynamic app = new AppConfig(); var configuration = new DataCacheFactoryConfiguration(); DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); _factory = new DataCacheFactory(configuration); _cache = _factory.GetDefaultCache(); }
private static DataCache GetCache() { if (_cache != null) { return(_cache); } // Disable tracing to avoid informational / verbose messages on the web page DataCacheClientLogManager.ChangeLogLevel(TraceLevel.Off); _factory = new DataCacheFactory(); _cache = _factory.GetDefaultCache(); return(_cache); }
public static DataCache GetCache() { if (_cache != null) { return(_cache); } //------------------------- // Configure Cache Client //------------------------- /* * //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("WINAPP1", 22233)); * //servers.Add(new DataCacheServerEndpoint("WINAPP2", 22233)); * //servers.Add(new DataCacheServerEndpoint("WINAPP4", 22233)); * //DataCacheSecurity dcs = new DataCacheSecurity( * * //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(TraceLevel.Info); //Pass configuration settings to cacheFactory constructor //_factory = new DataCacheFactory(configuration); _factory = new DataCacheFactory(); //Get reference to named cache called "default" _cache = _factory.GetCache("default"); return(_cache); }
public void Initialize() { var hostName = ConfigurationManager.AppSettings["CacheHost"] ?? "localhost"; var cachePort = string.IsNullOrEmpty(ConfigurationManager.AppSettings["CachePort"]) ? 22233 : int.Parse(ConfigurationManager.AppSettings["CachePort"]); var cacheName = ConfigurationManager.AppSettings["CacheName"] ?? "default"; List <DataCacheServerEndpoint> servers = new List <DataCacheServerEndpoint>(1); servers.Add(new DataCacheServerEndpoint(hostName, cachePort)); DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration(); configuration.TransportProperties.MaxBufferSize = Int32.MaxValue; configuration.TransportProperties.MaxBufferPoolSize = Int32.MaxValue; configuration.Servers = servers; configuration.LocalCacheProperties = new DataCacheLocalCacheProperties(10000, new TimeSpan(0, 5, 0), DataCacheLocalCacheInvalidationPolicy.TimeoutBased); DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); cacheFactory = new DataCacheFactory(configuration); defaultCache = cacheFactory.GetCache(cacheName); }
public DataCache ConstructCache(string endPointConfig) { #if NET35 if (string.IsNullOrEmpty(endPointConfig)) { endPointConfig = DEFAULT_EndpointConfig; } #else if (string.IsNullOrWhiteSpace(endPointConfig)) { endPointConfig = DEFAULT_EndpointConfig; } #endif var endPoints = ParseConfig(endPointConfig); var dataCacheEndpoints = new List <DataCacheServerEndpoint>(); endPoints.ForEach(e => dataCacheEndpoints.Add(new DataCacheServerEndpoint(e.IPAddressOrHostName, e.Port))); var config = new DataCacheFactoryConfiguration(); config.Servers = dataCacheEndpoints; SetSecuritySettings(config); try { var factory = new DataCacheFactory(config); DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Error); // Note: When setting up AppFabric. The configured cache needs to be created by the admin using the New-Cache powershell command //var cache = factory.GetCache(WebConfigSettings.DistributedCacheName); var cache = factory.GetDefaultCache(); return(cache); } catch (Exception ex) { log.Error(ex); throw; } }
/// <summary> /// 生成缓存访问对象 /// </summary> /// <returns></returns> public DataCache GetAppfabricCache() { if (_memCache != null) { return(_memCache); } //Create cache configuration DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration(); //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.Info); //Pass configuration settings to cacheFactory constructor if (_factory == null) { _factory = new DataCacheFactory(configuration); } if (string.IsNullOrWhiteSpace(CacheName)) { CacheName = System.Configuration.ConfigurationManager.AppSettings["CacheName"]; if (string.IsNullOrWhiteSpace(CacheName)) { CacheName = "default"; } } //Get reference to named cache called "default" _memCache = _factory.GetCache(CacheName); return(_memCache); }
static AppCache() { List <DataCacheServerEndpoint> servers = new List <DataCacheServerEndpoint>(1); servers.Add(new DataCacheServerEndpoint("ServerName", 22233)); //22233 is the default port DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration { Servers = servers, LocalCacheProperties = new DataCacheLocalCacheProperties(), SecurityProperties = new DataCacheSecurity(), RequestTimeout = new TimeSpan(0, 0, 300), MaxConnectionsToServer = 10, ChannelOpenTimeout = new TimeSpan(0, 0, 300), TransportProperties = new DataCacheTransportProperties() { MaxBufferSize = int.MaxValue, MaxBufferPoolSize = long.MaxValue } }; DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); var _factory = new DataCacheFactory(configuration); Cache = _factory.GetCache("MyCache"); }