private void SetSecuritySettings(DataCacheFactoryConfiguration config) { string securityModeValue = WebConfigSettings.AzureCacheSecurityMode.ToLowerInvariant(); string securityAuthValue = WebConfigSettings.AzureCacheAuthorizationInfo; bool useSsl = WebConfigSettings.AzureCacheUseSsl; DataCacheSecurity securityProps; switch (securityModeValue) { case "message": if (securityAuthValue.Length > 0) { SecureString secureToken = new SecureString(); foreach (var ch in securityAuthValue) { secureToken.AppendChar(ch); } securityProps = new DataCacheSecurity(secureToken, useSsl); config.SecurityProperties = securityProps; } break; case "transport": securityProps = new DataCacheSecurity(DataCacheSecurityMode.Transport,DataCacheProtectionLevel.None); config.SecurityProperties = securityProps; break; } }
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; } }
private void SetSecuritySettings(DataCacheFactoryConfiguration config) { string securityModeValue = WebConfigSettings.AzureCacheSecurityMode.ToLowerInvariant(); string securityAuthValue = WebConfigSettings.AzureCacheAuthorizationInfo; bool useSsl = WebConfigSettings.AzureCacheUseSsl; DataCacheSecurity securityProps; switch (securityModeValue) { case "message": if (securityAuthValue.Length > 0) { SecureString secureToken = new SecureString(); foreach (var ch in securityAuthValue) { secureToken.AppendChar(ch); } securityProps = new DataCacheSecurity(secureToken, useSsl); config.SecurityProperties = securityProps; } break; case "transport": securityProps = new DataCacheSecurity(DataCacheSecurityMode.Transport, DataCacheProtectionLevel.None); config.SecurityProperties = securityProps; break; } }
private DataCache GetDataCache(string name) { DataCache cache = null; HandleBadDataCacheBug(() => { var factorySecurity = new DataCacheSecurity(EnvironmentUtils.GetConfigSettingStr("AzureCache_Token")); var factoryConfig = new DataCacheFactoryConfiguration(); factoryConfig.SecurityProperties = factorySecurity; factoryConfig.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, EnvironmentUtils.GetConfigSettingStr( "AzureCache_Endpoint")); factoryConfig.UseLegacyProtocol = false; factoryConfig.MaxConnectionsToServer = 1; factoryConfig.ChannelOpenTimeout = TimeSpan.FromSeconds(3); factoryConfig.RequestTimeout = TimeSpan.FromSeconds(3); factoryConfig.IsCompressionEnabled = true; var dataCacheFactory = new DataCacheFactory(factoryConfig); cache = dataCacheFactory.GetCache(name); }); return(cache); }
public OutOfProcessMemoryCache() { var configuration = new DataCacheFactoryConfiguration(); var factory = new DataCacheFactory(configuration); cache = factory.GetCache(CacheName); }
public ProductsRepository(bool enableCache, bool enableLocalCache) { this.enableCache = enableCache; this.enableLocalCache = enableLocalCache; if (enableCache) { if (enableLocalCache && (factoryConfig == null || !factoryConfig.LocalCacheProperties.IsEnabled)) { TimeSpan localTimeout = new TimeSpan(0, 0, 30); DataCacheLocalCacheProperties localCacheConfig = new DataCacheLocalCacheProperties(10000, localTimeout, DataCacheLocalCacheInvalidationPolicy.TimeoutBased); factoryConfig = new DataCacheFactoryConfiguration(); factoryConfig.LocalCacheProperties = localCacheConfig; cacheFactory = new DataCacheFactory(factoryConfig); } else if (!enableLocalCache && (factoryConfig == null || factoryConfig.LocalCacheProperties.IsEnabled)) { cacheFactory = null; } } if (cacheFactory == null) { factoryConfig = new DataCacheFactoryConfiguration(); cacheFactory = new DataCacheFactory(factoryConfig); } }
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; }
static CacheFactory() { if (dataCacheFactory != null) { return; } redisCs = CloudConfigurationManager.GetSetting("redisCacheConnectionString"); var cacheSystem = (CloudConfigurationManager.GetSetting("cacheSystem") ?? "").ToLowerInvariant(); var cacheName = CloudConfigurationManager.GetSetting("azureCacheName"); if (cacheSystem == "azure") { cacheType = CacheType.Azure; var config = new DataCacheFactoryConfiguration(cacheName); // Default is 15 seconds - see http://msdn.microsoft.com/en-us/library/ee790816(v=azure.10).aspx config.RequestTimeout = TimeSpan.FromSeconds(10); dataCacheFactory = new DataCacheFactory(config); } else if (cacheSystem == "redis") { cacheType = CacheType.Redis; } else if (cacheSystem == "passthrough") { cacheType = CacheType.PassThrough; } else { cacheType = CacheType.Simple; } }
private void PrepareClient(bool sslEnabled) { string hostName = "[Cache endpoint without port]"; //Example : "MyCache.cache.appfabric.com"; int cachePort; cachePort = sslEnabled ? 22243 : 22233; // Default port List <DataCacheServerEndpoint> server = new List <DataCacheServerEndpoint>(); server.Add(new DataCacheServerEndpoint(hostName, cachePort)); DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration(); // Uncomment the lines below to use the authentication token in plain text. // ////string authenticationToken = "[InsertAuthenticationTokenHere]"; ////SecureString secureAuthenticationToken = GetSecureString(authenticationToken); // Load Auth token from settings SecureString secureAuthenticationToken = LoadAuthTokenFromSettings(); config.SecurityProperties = new DataCacheSecurity(secureAuthenticationToken, sslEnabled); config.Servers = server; config.LocalCacheProperties = new DataCacheLocalCacheProperties(10000, new TimeSpan(0, 5, 0), DataCacheLocalCacheInvalidationPolicy.TimeoutBased); DataCacheFactory myCacheFactory = new DataCacheFactory(config); myDefaultCache = myCacheFactory.GetDefaultCache(); }
/// <summary> /// Initializes a new instance of the <see cref="ReliableCloudCacheStorage"/> class using the specified storage account information, custom retry policy /// and custom implementation of <see cref="ICloudStorageEntitySerializer"/> interface. /// </summary> /// <param name="endpointInfo">The endpoint details for Windows Azure Caching Service.</param> /// <param name="retryPolicy">The custom retry policy that will ensure reliable access to the Caching Service.</param> /// <param name="dataSerializer">An instance of the component which performs custom serialization and deserialization of cache items.</param> public ReliableCloudCacheStorage(CachingServiceEndpointInfo endpointInfo, RetryPolicy retryPolicy, ICloudStorageEntitySerializer dataSerializer) { Guard.ArgumentNotNull(endpointInfo, "endpointInfo"); Guard.ArgumentNotNull(retryPolicy, "retryPolicy"); Guard.ArgumentNotNull(dataSerializer, "dataSerializer"); this.retryPolicy = retryPolicy; this.dataSerializer = dataSerializer; var cacheServers = new List <DataCacheServerEndpoint>(1); cacheServers.Add(new DataCacheServerEndpoint(endpointInfo.ServiceHostName, endpointInfo.CachePort)); var cacheConfig = new DataCacheFactoryConfiguration() { Servers = cacheServers, MaxConnectionsToServer = 1, IsCompressionEnabled = false, SecurityProperties = new DataCacheSecurity(endpointInfo.SecureAuthenticationToken, endpointInfo.SslEnabled), // As per recommendations in http://blogs.msdn.com/b/akshar/archive/2011/05/01/azure-appfabric-caching-errorcode-lt-errca0017-gt-substatus-lt-es0006-gt-what-to-do.aspx TransportProperties = new DataCacheTransportProperties() { ReceiveTimeout = TimeSpan.FromSeconds(45) } }; this.cacheFactory = new DataCacheFactory(cacheConfig); this.cache = this.retryPolicy.ExecuteAction <DataCache>(() => { return(this.cacheFactory.GetDefaultCache()); }); }
public AzureCacheClient(string cacheName = null, string endpointUrl = null, string authorizationToken = null, bool useLocalCache = true) { if (!String.IsNullOrEmpty(endpointUrl) && !String.IsNullOrEmpty(authorizationToken)) { var config = new DataCacheFactoryConfiguration { AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, endpointUrl), SecurityProperties = new DataCacheSecurity(authorizationToken, false) }; if (useLocalCache) { config.LocalCacheProperties = new DataCacheLocalCacheProperties(10000, TimeSpan.FromMinutes(5), DataCacheLocalCacheInvalidationPolicy.TimeoutBased); } CacheFactory = new DataCacheFactory(config); } else { CacheFactory = new DataCacheFactory(); } if (string.IsNullOrEmpty(cacheName)) { DataCache = CacheFactory.GetDefaultCache(); } else { DataCache = CacheFactory.GetCache(cacheName); } }
/// <summary> /// Do not use this constructor. Use MdCache.Instance instead. /// </summary> public AzureMdCache(MdCacheConfig config) { Validate.NotNull(config, "config"); _config = config; DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration() { SerializationProperties = new DataCacheSerializationProperties( DataCacheObjectSerializerType.CustomSerializer, new AzureMdCacheSerializer() ), IsCompressionEnabled = true, AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, config.Identifier) }; if (!string.IsNullOrEmpty(config.AuthorizationToken)) { factoryConfig.SecurityProperties = new DataCacheSecurity(config.AuthorizationToken); } DataCacheFactory factory = new DataCacheFactory(factoryConfig); _dataCache = factory.GetCache(config.CacheName); }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { try { string cacheName = ConfigurationManager.AppSettings["CacheName"] ?? "default"; string region = ConfigurationManager.AppSettings["LogRegion"]; DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration(); DataCacheFactory factory = new DataCacheFactory(); DataCache cache = factory.GetCache(cacheName); List<KeyValuePair<string, object>> objects = cache.GetObjectsInRegion(region).ToList(); logEntries = new List<KeyValuePair<long, string>>(); for (int i = 0; i < objects.Count; i++) { long key; if (long.TryParse(objects[i].Key, out key)) { logEntries.Add(new KeyValuePair<long, string>(key, objects[i].Value.ToString())); } } logEntries.Sort((a, b) => a.Key.CompareTo(b.Key)); Grid.ItemsSource = logEntries; } catch (Exception ex) { MessageBox.Show("Error getting objects from cache: " + ex.Message); } }
public static DataCache GetCache() { if (_cache != null) { return _cache; } //Define Array for 1 Cache Host var servers = new List<DataCacheServerEndpoint>(1); //Specify Cache Host Details // Parameter 1 = host name // Parameter 2 = cache port number servers.Add(new DataCacheServerEndpoint("DevMongoDB2", 22233)); //Create cache configuration var configuration = new DataCacheFactoryConfiguration { Servers = servers, 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); _factory = new DataCacheFactory(configuration: configuration); //Get reference to named cache called "default" _cache = _factory.GetCache("default"); 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 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); }
internal void MapSettingsFromConfigToAppFabricSettings(CacheConfig config, DataCacheFactoryConfiguration factoryConfig) { SetSecuritySettings(config, factoryConfig); SetMaxConnectionsToServer(config, factoryConfig); SetChannelOpenTimeout(config, factoryConfig); SetLocalCacheConfiguration(config, factoryConfig); }
// // GET: /Cache/ public ActionResult Index() { DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration(); DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1] { new DataCacheServerEndpoint(factoryConfig.Servers.First().HostName, 22233) }; factoryConfig.Servers = servers; DataCacheFactory mycacheFactory = new DataCacheFactory(factoryConfig); DataCache cache = mycacheFactory.GetCache("default"); var list = new List<CacheEntryViewModel>(); if (cache.Get("Time") == null) { cache.Put("Time", DateTime.Now); } list.Add(new CacheEntryViewModel() { Key= "Time", Value = ((DateTime)cache.Get("Time")).ToLongTimeString() }); return View(list); }
public RemoteCache(IEnumerable<string> cacheServers, int timeoutMilliseconds = 2000, string cacheName = "default", string regionName = "default") { _timeout = timeoutMilliseconds; _cacheRegion = regionName; var servers = cacheServers.Select(serverName => new DataCacheServerEndpoint(serverName, 22233)).ToList(); //Create cache configuration //Set the cache host(s) //Set default properties for local cache (local cache disabled) var factoryConfiguration = new DataCacheFactoryConfiguration { Servers = servers, LocalCacheProperties = new DataCacheLocalCacheProperties(), ChannelOpenTimeout = Timespan, RequestTimeout = Timespan, TransportProperties = new DataCacheTransportProperties() { ChannelInitializationTimeout = Timespan, ReceiveTimeout = Timespan } }; //Disable tracing to avoid informational/verbose messages on the web page DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); //_cache = ConnectCacheRx(cacheName, factoryConfiguration).Timeout(Timespan).Single(); ThreadPool.QueueUserWorkItem(_ => ConnectCache(cacheName, factoryConfiguration)); if(!_cacheConnected.WaitOne(_timeout)) throw new TimeoutException("Could Not Connect to AppFabric Server at: " + String.Join(", ", cacheServers)); }
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 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 AzureCacheManager() { _cacheFactory = new Lazy<DataCacheFactory>(() => { DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration(ClientName); return new DataCacheFactory(config); }, LazyThreadSafetyMode.ExecutionAndPublication); }
public AzureCacheManager() { _cacheFactory = new Lazy <DataCacheFactory>(() => { DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration(ClientName); return(new DataCacheFactory(config)); }, LazyThreadSafetyMode.ExecutionAndPublication); }
/// <summary> /// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class. /// </summary> /// <param name="configuration">The AbbFabric Caching configuration.</param> /// <param name="cacheName">Name of the cache.</param> public AppFabricCachingProvider(DataCacheFactoryConfiguration configuration, string cacheName = null) : this(new DataCacheFactory(configuration), cacheName) { if (configuration == null) { throw new ArgumentNullException("configuration"); } }
private static bool PrepareClient(string server_name) { lastErrorMessage = String.Empty; try { //------------------------- // Configure Cache Client //------------------------- //Define Array for 1 Cache Host List <DataCacheServerEndpoint> servers = new List <DataCacheServerEndpoint>(1) { new DataCacheServerEndpoint(server_name, 22233) }; //Specify Cache Host Details // Parameter 1 = host name // Parameter 2 = cache port number //Create cache configuration DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration { Servers = servers, SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None), LocalCacheProperties = new DataCacheLocalCacheProperties() }; //Disable exception messages since this sample works on a cache aside //DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); //Pass configuration settings to cacheFactory constructor myCacheFactory = new DataCacheFactory(configuration); //Get reference to named cache called "default" myDefaultCache = myCacheFactory.GetCache("default"); //specify all possible item and region operations const DataCacheOperations itemCacheOperations = DataCacheOperations.AddItem | DataCacheOperations.ReplaceItem | DataCacheOperations.RemoveItem | DataCacheOperations.ClearRegion | DataCacheOperations.CreateRegion; //add cache-level notification callback //all cache operations from a notifications-enabled cache DataCacheNotificationDescriptor ndCacheLvlAllOps = myDefaultCache.AddRegionLevelCallback("SobekCM", itemCacheOperations, myCacheLvlDelegate); myDefaultCache.CreateRegion(regionName); return(true); } catch (Exception ee) { lastErrorMessage = ee.Message; return(false); } }
public void Connect(int storedCredentialIndex, CredentialsHelper credentialsHelper, string cacheName) { CacheInteractionStartBusy(this, new CacheInteractionStartBusyEventArgs("Connecting...")); DataCacheFactoryConfiguration config = credentialsHelper.GetDataCacheConfiguration(storedCredentialIndex); DataCacheFactory fac = new DataCacheFactory(config); _cache = fac.GetCache(cacheName); CacheInteractionEndBusy(this, new CacheInteractionEndBusyEventArgs()); }
private static DataCache GetCache() { if (_cache != null) return _cache; var configuration = new DataCacheFactoryConfiguration(); _factory = new DataCacheFactory(configuration); _cache = _factory.GetCache("default"); return _cache; }
public AzureCache() { if (cache == null) { DataCacheFactoryConfiguration cfg = new DataCacheFactoryConfiguration(); cfg.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, "CacheWorkerRole1"); dataCacheFactory = new DataCacheFactory(cfg); cache = dataCacheFactory.GetDefaultCache(); } }
private static DataCache GetCache() { var cacheConfig = new DataCacheFactoryConfiguration("default") {MaxConnectionsToServer = 6}; DataCacheFactoryConfiguration.CreateNamedConfiguration("ConfigWithConnectionPooling", cacheConfig, true); var configWithPooling = new DataCacheFactoryConfiguration("ConfigWithConnectionPooling"); var factory = new DataCacheFactory(configWithPooling); return factory.GetDefaultCache(); }
private static DataCache GetCache() { if (_cache != null) { return(_cache); } var config = new DataCacheFactoryConfiguration(); _factory = new DataCacheFactory(config); return(_cache = _factory.GetCache("default")); }
private static ICache CreateAppFabricCache() { var server = new List<DataCacheServerEndpoint>(); server.Add(new DataCacheServerEndpoint("localhost", 22233)); var conf = new DataCacheFactoryConfiguration(); conf.Servers = server; DataCacheFactory fac = new DataCacheFactory(conf); return new AppFabricCache(fac.GetDefaultCache()); }
public CloudCacheService(IConfiguration configuration) { DataCacheFactoryConfiguration cacheConfig = new DataCacheFactoryConfiguration(); cacheConfig.Servers = new[] { new DataCacheServerEndpoint(configuration.AzureCacheEndpoint, 22233) }; SecureString key = configuration.AzureCacheKey.ToSecureString(); DataCacheSecurity security = new DataCacheSecurity(key); cacheConfig.SecurityProperties = security; _cacheFactory = new DataCacheFactory(cacheConfig); }
private void SetMaxConnectionsToServer(CacheConfig config, DataCacheFactoryConfiguration factoryConfig) { if (config.ProviderSpecificValues.ContainsKey(AppFabricConstants.CONFIG_MaxConnectionsToServer)) { int maxConnectionsToServer; if (int.TryParse(config.ProviderSpecificValues[AppFabricConstants.CONFIG_MaxConnectionsToServer], out maxConnectionsToServer)) { factoryConfig.MaxConnectionsToServer = maxConnectionsToServer; _logger.WriteInfoMessage(string.Format("AppFabric MaxConnectionsToServer: [{0}]", maxConnectionsToServer)); } } }
public static void TestSetUp() { var config = new DataCacheFactoryConfiguration { Servers = new List <DataCacheServerEndpoint> { new DataCacheServerEndpoint("C012A4700", 22233) } }; var factory = new DataCacheFactory(config); cache = factory.GetCache(CacheName); }
public static void TestSetUp() { var config = new DataCacheFactoryConfiguration { Servers = new List<DataCacheServerEndpoint> { new DataCacheServerEndpoint("C012A4700", 22233) } }; var factory = new DataCacheFactory(config); cache = factory.GetCache(CacheName); }
// It creates a DataCache object which is mapped to AppFabricServer. private static DataCache GetCache() { if (_cache != null) { return(_cache); } var configuration = new DataCacheFactoryConfiguration(); _factory = new DataCacheFactory(configuration); _cache = _factory.GetCache(Convert.ToString(ConfigurationManager.AppSettings["CacheName"])); return(_cache); }
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 ICache CreateAppFabricCache() { var server = new List <DataCacheServerEndpoint>(); server.Add(new DataCacheServerEndpoint("localhost", 22233)); var conf = new DataCacheFactoryConfiguration(); conf.Servers = server; DataCacheFactory fac = new DataCacheFactory(conf); return(new AppFabricCache(fac.GetDefaultCache())); }
public DataCacheFactory CreateCache() { var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration { UseLegacyProtocol = false, IsCompressionEnabled = CompressionIsEnabled }; dataCacheFactoryConfiguration.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, HostIdentifier); if (!String.IsNullOrEmpty(AuthorizationToken)) dataCacheFactoryConfiguration.SecurityProperties = new DataCacheSecurity(AuthorizationToken, sslEnabled: false); return new DataCacheFactory(dataCacheFactoryConfiguration); }
private static DataCacheFactoryConfiguration GetDataCacheFactoryConfiguration() { SPDistributedCacheClusterInfoManager local = SPDistributedCacheClusterInfoManager.Local; SPDistributedCacheClusterInfo sPDistributedCacheClusterInfo = local.GetSPDistributedCacheClusterInfo(SPDistributedCacheClusterConfigHelper.SPDistributedCacheClusterName); var settings = local.GetSPDistributedCacheClientConfigurationSettings( SPDistributedCacheContainerType.DistributedDefaultCache); SPDistributedCacheHostInfoCollection cacheHostsInfoCollection = sPDistributedCacheClusterInfo.CacheHostsInfoCollection; var list = new List <DataCacheServerEndpoint>(); foreach (SPDistributedCacheHostInfo current in cacheHostsInfoCollection) { //DiagnosticLog.Info("GetAllDataCacheServerEndpointsForFarm", current.HostName); if (current.CacheHostStatus == SPDistributedCacheHostStatus.UP) { list.Add(new DataCacheServerEndpoint(current.HostName, current.CachePort)); } } if (list.Count == 0) { throw new InvalidOperationException( "InitializeDataCacheFactory - No cache hosts are present or running in the farm."); } var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration { DataCacheServiceAccountType = SPServer.LocalServerRole == SPServerRole.SingleServer ? DataCacheServiceAccountType.SystemAccount : DataCacheServiceAccountType.DomainAccount, Servers = list, ChannelOpenTimeout = settings.ChannelOpenTimeOut, RequestTimeout = settings.RequestTimeout, MaxConnectionsToServer = settings.MaxConnectionsToServer, TransportProperties = { ChannelInitializationTimeout = settings.ChannelInitializationTimeout, ConnectionBufferSize = settings.ConnectionBufferSize, MaxBufferPoolSize = settings.MaxBufferPoolSize, MaxBufferSize = settings.MaxBufferSize, MaxOutputDelay = settings.MaxOutputDelay, ReceiveTimeout = settings.ReceiveTimeout }, SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.Transport, DataCacheProtectionLevel.EncryptAndSign), LocalCacheProperties = new DataCacheLocalCacheProperties(), NotificationProperties = new DataCacheNotificationProperties(10000L, TimeSpan.FromSeconds(5.0)) }; return(dataCacheFactoryConfiguration); }
public DataCacheFactory CreateCache() { var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration { UseLegacyProtocol = false, IsCompressionEnabled = CompressionIsEnabled }; dataCacheFactoryConfiguration.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, HostIdentifier); if (!String.IsNullOrEmpty(AuthorizationToken)) { dataCacheFactoryConfiguration.SecurityProperties = new DataCacheSecurity(AuthorizationToken, sslEnabled: false); } return(new DataCacheFactory(dataCacheFactoryConfiguration)); }
public AppFabricCache() { if (!velocityCacheName.IsNullEmpty()) { DataCacheServerEndpoint[] cluster = GetClusterEndpoints(); DataCacheFactoryConfiguration cfg = new DataCacheFactoryConfiguration(); cfg.Servers = cluster; cfg.LocalCacheProperties = new DataCacheLocalCacheProperties(); cfg.SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None); _factory = new DataCacheFactory(cfg); _cache = _factory.GetCache(velocityCacheName); try { _cache.CreateRegion(RegionName); } catch { } } }
/// <summary> /// Initializes this instance. /// </summary> private void Init(string namedCache) { DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration(namedCache); config.IsCompressionEnabled = true; //config.MaxConnectionsToServer = 100000; config.RequestTimeout = TimeSpan.FromSeconds(10); DataCacheFactory factory = new DataCacheFactory(config); this.cache = factory.GetCache(namedCache); this.cache.CreateRegion("ip"); }
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { var server = new List<DataCacheServerEndpoint>(); server.Add(new DataCacheServerEndpoint("localhost", 22233)); var conf = new DataCacheFactoryConfiguration(); conf.Servers = server; DataCacheFactory dataCacheFactory = new DataCacheFactory(conf); foreach (OperationDescription operation in endpoint.Contract.Operations) { if (operation.Behaviors.Contains(typeof(FabricCacheOperationInvokerOperationBehavior))) { continue; } operation.Behaviors.Add(new FabricCacheOperationInvokerOperationBehavior(dataCacheFactory)); } }
public static AppFabricCacheProvider GetInstance() { lock (locker) { if (instance == null) { var configuration = new DataCacheFactoryConfiguration(); instance = new AppFabricCacheProvider(); configuration.SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None); DataCacheFactory factory = new DataCacheFactory(configuration); string cacheName = ConfigurationSettings.AppSettings["CacheName"]; cache = factory.GetCache(cacheName); } } return instance; }
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 CreateCache() { var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration { MaxConnectionsToServer = 32, UseLegacyProtocol = false, IsCompressionEnabled = CompressionIsEnabled }; dataCacheFactoryConfiguration.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, HostIdentifier); if (!String.IsNullOrEmpty(AuthorizationToken)) dataCacheFactoryConfiguration.SecurityProperties = new DataCacheSecurity(AuthorizationToken, sslEnabled: false); var dataCacheFactory = new DataCacheFactory(dataCacheFactoryConfiguration); if (!String.IsNullOrEmpty(CacheName)) { return dataCacheFactory.GetCache(CacheName); } return dataCacheFactory.GetDefaultCache(); }
static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(OrganizitionService))) { host.Open(); var server = new List<DataCacheServerEndpoint>(); server.Add(new DataCacheServerEndpoint("localhost", 22233)); // Set up the DataCacheFactory configuration var conf = new DataCacheFactoryConfiguration(); conf.Servers = server; DataCacheFactory factory = new DataCacheFactory(conf); //foreach (var operation in host.Description.Endpoints[0].Contract.Operations) //{ // operation.Behaviors.Add(new FabricCacheOperationInvoker(factory)); //} Console.WriteLine("Service is running"); Console.Write("Press ENTER to close the host"); Console.ReadLine(); host.Close(); } }
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(System.Environment.MachineName, 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(); //configuration.ChannelOpenTimeout = System.TimeSpan.FromMinutes(2); configuration.RequestTimeout = TimeSpan.FromSeconds(1); configuration.ChannelOpenTimeout = TimeSpan.FromSeconds(45); configuration.TransportProperties.ReceiveTimeout = TimeSpan.FromSeconds(45); configuration.TransportProperties.ChannelInitializationTimeout = TimeSpan.FromSeconds(10); configuration.MaxConnectionsToServer = 1; //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(string name) { if (_cache != null) return _cache; if (String.IsNullOrEmpty(name) == true) name = "default"; List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1); servers.Add(new DataCacheServerEndpoint("sead-gbyd1r1-x2", 22233)); servers.Add(new DataCacheServerEndpoint("tac-vdi087", 22233)); DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration(); // Set notification properties in the config: configuration.NotificationProperties = new DataCacheNotificationProperties(10000, new TimeSpan(0, 0, 5)); configuration.Servers = servers; configuration.LocalCacheProperties = new DataCacheLocalCacheProperties(); DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); _factory = new DataCacheFactory(configuration); _cache = _factory.GetCache(name); return _cache; }
public override void Run() { // @TODO //May be this code should be moved to global.asax.cs //Build the cache here when the web role run is invoked. // Create a DataCacheFactoryConfiguration object DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration(); // Enable the AutoDiscorveryProperty (and any other required configuration settings): config.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, "Skewrl.Web.Core"); // Create a DataCacheFactory object with the configuration settings: DataCacheFactory factory = new DataCacheFactory(config); // Use the factory to create a DataCache client for the "default" cache: DataCache cache = factory.GetCache("default"); IUrlMapDataSource urlDS = UnityConfig.Instance.Resolve<IUrlMapDataSource>(); // A good strategy would be load as much you can depending upon the VM and then implement // atleast one of the MRU algorithms foreach (UrlMap url in urlDS.FindTop100Mappings()) { cache.Add(url.ShortUrlCode, url.OriginalUrl); } /* * +------------------------------------------------------------------------+ * | Let this be the last statement. | * | Technically Run() is not supposed to return immediately unless as role | * | is expected to Run for ever. | * | Calling the base.Run() method will ensure this won't be recycled. | * +------------------------------------------------------------------------+ */ base.Run(); }
private void PrepareClient() { //------------------------- // 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("US3379028W1", 22233)); //Create cache configuration DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration(); //Set the cache host(s) configuration.Servers = servers; configuration.SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None); //Set default properties for local cache (local cache disabled) configuration.LocalCacheProperties = new DataCacheLocalCacheProperties(); //Disable exception messages since this sample works on a cache aside DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); //Pass configuration settings to cacheFactory constructor myCacheFactory = new DataCacheFactory(configuration); //Get reference to named cache called "default" myDefaultCache = myCacheFactory.GetCache("default"); }
private static void ConnectCache(string cacheName, DataCacheFactoryConfiguration config) { try { var factory = new DataCacheFactory(config); _cache = factory.GetCache(cacheName); _cache.CreateRegion(_cacheRegion); _cacheConnected.Set(); } catch { ; } }
private void InitializeCache() { String cacheNamespace = RoleEnvironment.GetConfigurationSettingValue("Namespace"); String cacheHost = String.Format("{0}.cache.windows.net", cacheNamespace); Boolean SslEnabled = true; Int32 cachePort = SslEnabled ? 22243 : 22233; Int32 sizeLocalCache = 100; DataCacheLocalCacheProperties localCacheProperties = new DataCacheLocalCacheProperties( sizeLocalCache, TimeSpan.FromSeconds(60), DataCacheLocalCacheInvalidationPolicy.TimeoutBased); List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(); servers.Add(new DataCacheServerEndpoint(cacheHost, cachePort)); DataCacheTransportProperties dataCacheTransportProperties = new DataCacheTransportProperties() { MaxBufferSize = 10000, ReceiveTimeout = TimeSpan.FromSeconds(45) }; DataCacheFactoryConfiguration cacheFactoryConfiguration = new DataCacheFactoryConfiguration() { LocalCacheProperties = localCacheProperties, SecurityProperties = GetSecurityToken(SslEnabled), Servers = servers, TransportProperties = dataCacheTransportProperties }; DataCacheFactory dataCacheFactory = new DataCacheFactory(cacheFactoryConfiguration); dataCache = dataCacheFactory.GetDefaultCache(); }
public OutOfProcessMemoryCache() { var configuration = new DataCacheFactoryConfiguration(); var factory = new DataCacheFactory(configuration); _cache = factory.GetCache(CacheName); }
/// <summary> /// Initializes a new instance of the <see cref="ServerAppFabricServiceCache"/> class. /// </summary> /// <param name="configuration">The configuration.</param> public ServerAppFabricServiceCache(DataCacheFactoryConfiguration configuration) : this(new DataCacheFactory(configuration)) { }
public override void ActivateOptions() { base.ActivateOptions(); try { DataCacheFactory factory; if (this.Hosts.Count != 0) { LogLog.Debug(declaringType, "Activating host options"); DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration(); List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(); for (int i = 0; i < this.Hosts.Count; i++) { servers.Add(new DataCacheServerEndpoint(this.Hosts[i].Host, this.Hosts[i].Port)); } config.Servers = servers; factory = new DataCacheFactory(config); } else { LogLog.Debug(declaringType, "No host options detected, using default cache factory"); factory = new DataCacheFactory(); } _Cache = factory.GetCache(this.CacheName); //config region exists before we attempt to write to it. _Cache.CreateRegion(this.RegionName); var obj = _Cache.Get(Shared.LAST_PUSHED_KEY_KEY, this.RegionName); if (obj == null) { _Cache.Put(Shared.LAST_PUSHED_KEY_KEY, "0", this.RegionName); } } catch (Exception ex) { this.ErrorHandler.Error("Could not create connection to App Fabric", ex); this._Cache = null; } }
private static bool PrepareClient(string server_name) { lastErrorMessage = String.Empty; try { //------------------------- // Configure Cache Client //------------------------- //Define Array for 1 Cache Host List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1) {new DataCacheServerEndpoint(server_name, 22233)}; //Specify Cache Host Details // Parameter 1 = host name // Parameter 2 = cache port number //Create cache configuration DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration { Servers = servers, SecurityProperties =new DataCacheSecurity( DataCacheSecurityMode.None, DataCacheProtectionLevel.None), LocalCacheProperties = new DataCacheLocalCacheProperties() }; //Disable exception messages since this sample works on a cache aside //DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off); //Pass configuration settings to cacheFactory constructor myCacheFactory = new DataCacheFactory(configuration); //Get reference to named cache called "default" myDefaultCache = myCacheFactory.GetCache("default"); //specify all possible item and region operations const DataCacheOperations itemCacheOperations = DataCacheOperations.AddItem | DataCacheOperations.ReplaceItem | DataCacheOperations.RemoveItem | DataCacheOperations.ClearRegion | DataCacheOperations.CreateRegion; //add cache-level notification callback //all cache operations from a notifications-enabled cache DataCacheNotificationDescriptor ndCacheLvlAllOps = myDefaultCache.AddRegionLevelCallback("SobekCM", itemCacheOperations, myCacheLvlDelegate); myDefaultCache.CreateRegion(regionName); return true; } catch ( Exception ee ) { lastErrorMessage = ee.Message; return false; } }