public object this[string key] { get { DataCache sessions = CacheFactory.GetCache(AppFabricSessions.CacheName); var session = sessions.Get(Id.ToString()) as IDictionary <string, object>; if (session != null && session.ContainsKey(key)) { return(session[key]); } return(null); } set { DataCache sessions = CacheFactory.GetCache(AppFabricSessions.CacheName); var session = sessions.Get(Id.ToString()) as IDictionary <string, object>; if (session != null) { session[key] = value; sessions.Put(Id.ToString(), session); } else { throw new InvalidOperationException("Session with session id: " + Id + " does not exist. Not able to add key: " + key + " and value: " + value + " to session."); } } }
protected override ISession GetSession() { ISession session = null; DataCache sessions = CacheFactory.GetCache(CacheName); if (SessionId.HasValue && sessions.Get(SessionId.ToString()) != null) { try { // Needed in order to simluate sliding expiration sessions.ResetObjectTimeout(SessionId.ToString(), new TimeSpan(0, 0, SessionTimeout, 0)); session = new AppFabricSession(SessionId.Value); // Ping user id cache to extend the timeout var userId = session[UserId] as string; if (!string.IsNullOrEmpty(userId)) { sessions.ResetObjectTimeout(userId, new TimeSpan(0, 0, SessionTimeout, 0)); } } catch (DataCacheException) { // Do nothing - call to sessions.ResetObjectTimeout will throw a DataCacheException if sessions have been removed by SOAP-Logout } } if (session == null) { session = new AppFabricSession(CreateSession()); session.New = true; } return(session); }
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; //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; } //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 void PrepareClient() { myCacheFactory = new DataCacheFactory(); var cacheName = ConfigurationManager.AppSettings["CacheId"]; myDefaultCache = myCacheFactory.GetCache(cacheName); }
// // 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); }
/// <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); } 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 OutOfProcessMemoryCache() { var configuration = new DataCacheFactoryConfiguration(); var factory = new DataCacheFactory(configuration); cache = factory.GetCache(CacheName); }
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 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 void RegisterCache() { var factory = new DataCacheFactory(); var dataCache = factory.GetCache(configuredCacheName); container.RegisterInstance(configuredCacheName, dataCache); container.RegisterAbsoluteCacheItemPolicyFactory(configuredCacheName); }
public WindowsAzureCacheProvider(DataCacheFactory cacheFactory, string cacheName = null) { Guard.AgainstNullArgument(cacheFactory); _dataChache = String.IsNullOrEmpty(cacheName) ? cacheFactory.GetDefaultCache() : cacheFactory.GetCache(cacheName); }
public AzureCacheService(ILogService logger, string cacheName) { _logger = logger; var cacheFactory = new DataCacheFactory(new DataCacheFactoryConfiguration(DataCacheClientConfigurationName)); _cache = cacheFactory.GetCache(cacheName); }
public AppFabricCache(string name) { Guard.ArgumentNotNullOrEmpty(name, "name"); _name = name; _dataCacheFactory = new DataCacheFactory(); _cache = _dataCacheFactory.GetCache(name); }
private DataCache GetDataCache(string cacheName) { if (dcf == null) { dcf = new DataCacheFactory(); } return(dcf.GetCache((ProductName + "_" + cacheName).ToUpper()) ?? dcf.GetDefaultCache()); }
public VelocityCache() { if (velocityCacheName.Length > 0) { _factory = new DataCacheFactory(); _cache = _factory.GetCache(velocityCacheName); try { _cache.CreateRegion(RegionName, false); } catch { } } }
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()); }
protected override void InitialiseInternal() { if (_cache == null) { var cacheName = CacheConfiguration.Current.DefaultCacheName.Replace(".", "-"); Log.Debug("AppFabricCache.Initialise - initialising with cache name: {0}", cacheName); _factory = new DataCacheFactory(); _cache = _factory.GetCache(cacheName); } }
private static DataCache GetCache() { if (_cache != null) return _cache; var configuration = new DataCacheFactoryConfiguration(); _factory = new DataCacheFactory(configuration); _cache = _factory.GetCache("default"); return _cache; }
private static DataCache GetCache() { if (_cache != null) { return(_cache); } var config = new DataCacheFactoryConfiguration(); _factory = new DataCacheFactory(config); return(_cache = _factory.GetCache("default")); }
private void PrepareClient() { //------------------------- // Configure Cache Client //------------------------- myCacheFactory = new DataCacheFactory(); var cacheName = ConfigurationManager.AppSettings["CacheId"]; //Get reference to named cache myDefaultCache = myCacheFactory.GetCache(cacheName); }
public AzureCacheClient(string cacheName = null) { CacheFactory = new DataCacheFactory(); if (string.IsNullOrEmpty(cacheName)) { DataCache = CacheFactory.GetDefaultCache(); } else { DataCache = CacheFactory.GetCache(cacheName); } }
/// <summary> /// Gets an instance of a data cache [client]. /// </summary> /// <param name="cacheName">The name of the AppFabric cache to get the data cache [client] for.</param> /// <returns>A data cache [client].</returns> public DataCache GetCache(string cacheName) { try { return(_cacheCluster.GetCache(cacheName)); } catch (DataCacheException ex) { _log.Error(ex.Message, ex); throw; } }
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 static AppFabricCacheProvider GetInstance() { lock (locker) { if (instance == null) { instance = new AppFabricCacheProvider(); DataCacheFactory factory = new DataCacheFactory(); cache = factory.GetCache("Default"); } } return(instance); }
/// <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 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 { } } }
static VelocityCacheResolver() { _Factory = new DataCacheFactory(); _Cache = _Factory.GetCache(ConstantHelper.VelocityCacheName); try { _Cache.CreateRegion(REGION_NAME, false); } catch { // if the region already exists, this will throw an exception. // Velocity has no API to check if a region exists or not. } }
private void btnConnect_Click(object sender, EventArgs e) { if (myCache == null) { try { DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1]; servers[0] = new DataCacheServerEndpoint(txtCacheServer.Text, int.Parse(txtPort.Text)); DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration(); factoryConfig.Servers = servers; if (!(checkBoxSecurity.Checked)) { DataCacheSecurity security = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None); factoryConfig.SecurityProperties = security; } //You must set the security authentication account type to DomainAccount on the client side //when the caching service identity is a domain account. The default type is SystemAccount. if (checkBoxDomainAcc.Checked) { factoryConfig.DataCacheServiceAccountType = DataCacheServiceAccountType.DomainAccount; } if (checkBoxLocalCache.Checked) { //TimeSpan localTimeout = new TimeSpan(0, 1, 0); TimeSpan localTimeout = TimeSpan.FromSeconds(Convert.ToDouble(txtTimeout.Text)); DataCacheLocalCacheProperties localCacheConfig = new DataCacheLocalCacheProperties(10000, localTimeout, DataCacheLocalCacheInvalidationPolicy.TimeoutBased); factoryConfig.LocalCacheProperties = localCacheConfig; } myCacheFactory = new DataCacheFactory(factoryConfig); myCache = myCacheFactory.GetCache(txtCacheName.Text); //this.Text = "AppFabric Test Client has connected to Cache Cluster..."; UpdateStatus("You have connected to the Cache Cluster."); lblConnectionStatus.Text = "CONNECTED"; } catch (Exception ex) { HandleException(ex); } } }
public DataCache GetCache() { if (_cache != null) return _cache; //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(); //Get reference to named cache called "default" _cache = _factory.GetCache("default"); return _cache; }
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); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Yellow; try { string cachename = "default"; string key = "KEY"; var val = DateTime.Now.ToString(); if (args != null) { if (args.Length == 1) cachename = args[0]; if (args.Length == 2) key = args[1]; if (args.Length == 3) val = args[2]; } Console.WriteLine("Initializing..."); DataCacheFactory dcf = new DataCacheFactory(); Console.WriteLine("Factory created."); Console.WriteLine("Connecting to cache '{0}'.", cachename); DataCache mycache = dcf.GetCache(cachename); Console.WriteLine("Connected successfully to cache."); mycache.Add(key, val); Console.WriteLine("Added value to cache {0}-{1}", key, val); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Cyan; trace(ex); } }
public void WaitForItemNotificationShouldGetBulkNotification() { var expectedKey = "Key" + TestContext.TestName; var expectedOldValue = "oldValue" + TestContext.TestName; var expectedNewValue = "newValue" + TestContext.TestName; var dcf = new DataCacheFactory(); var dc = dcf.GetCache(NotificationCacheName); // Create a workflow that waits for a notification var sut = WorkflowApplicationTest.Create(new WaitForCacheBulkNotification { CacheName = NotificationCacheName, }); // Will catch if the workflow aborts sut.Aborted = (args) => TestContext.WriteLine("Workflow Aborted {0}", args.Reason); sut.TestActivity(); // Wait for the workflow to go idle Assert.IsTrue(sut.WaitForIdleEvent(), "WaitForCacheBulkNotification did not go idle"); dc.Remove(expectedKey); dc.Add(expectedKey, expectedOldValue); // Update the item var expectedVersion = dc.Put(expectedKey, expectedNewValue); Assert.IsTrue(sut.WaitForCompletedEvent(2000), "WaitForCacheBulkNotification did not complete"); // Assert Out Arguments sut.AssertOutArgument.IsNotNull("NotificationDescriptor"); sut.AssertOutArgument.IsNotNull("Operations"); var operations = (IEnumerable<DataCacheOperationDescriptor>) sut.Results.Output["Operations"]; // Notifications are timing sensitive - the RemoveItem may or may not be included in the bulk get //Assert.AreEqual(DataCacheOperations.RemoveItem, operations.ElementAt(0).OperationType); //Assert.AreEqual(DataCacheOperations.AddItem, operations.ElementAt(1).OperationType); //Assert.AreEqual(DataCacheOperations.ReplaceItem, operations.ElementAt(2).OperationType); sut.Tracking.Trace(); }
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(); }
public void WaitForCacheNotificationShouldGetNotificationOnReplaceWithRegion() { var expectedKey = "Key" + TestContext.TestName; var expectedOldValue = "oldValue" + TestContext.TestName; var expectedNewValue = "newValue" + TestContext.TestName; var expectedRegion = "Region" + TestContext.TestName; var dcf = new DataCacheFactory(); var dc = dcf.GetCache(NotificationCacheName); dc.CreateRegion(expectedRegion); dc.Remove(expectedKey, expectedRegion); dc.Add(expectedKey, expectedOldValue, expectedRegion); // Create a workflow that waits for a notification var sut = WorkflowApplicationTest.Create(new WaitForRegionNotification { CacheName = NotificationCacheName, Filter = DataCacheOperations.ReplaceItem, Region = expectedRegion }); // Will catch if the workflow aborts sut.Aborted = (args) => TestContext.WriteLine("Workflow Aborted {0}", args.Reason); sut.TestActivity(); // Wait for the workflow to go idle Assert.IsTrue(sut.WaitForIdleEvent(), "WaitForRegionNotification did not go idle"); // Update the item var expectedVersion = dc.Put(expectedKey, expectedNewValue, expectedRegion); Assert.IsTrue(sut.WaitForCompletedEvent(2000), "WaitForRegionNotification did not complete"); // Assert Out Arguments sut.AssertOutArgument.IsNotNull("NotificationDescriptor"); sut.AssertOutArgument.AreEqual("Version", expectedVersion); sut.AssertOutArgument.AreEqual("CacheOperation", DataCacheOperations.ReplaceItem); sut.Tracking.Trace(); }
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 static DataCacheFactory _factory; static MatchingService() { DataCacheFactory factory = new DataCacheFactory(); _cache = factory.GetCache("default"); //Debug.Assert(_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; } }
public OutOfProcessMemoryCache() { var configuration = new DataCacheFactoryConfiguration(); var factory = new DataCacheFactory(configuration); _cache = factory.GetCache(CacheName); }
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"); }
static Program() { DataCacheFactory factory = new DataCacheFactory(); _cache = factory.GetCache("default"); //Debug.Assert(_cache == null); }
/// <summary> /// Initializes a new instance of the <see cref="ServerAppFabricServiceCache"/> class. /// </summary> /// <param name="cacheFactory">The cache factory.</param> /// <param name="cacheName">Name of the cache.</param> public ServerAppFabricServiceCache(DataCacheFactory cacheFactory, string cacheName) : this(cacheFactory.GetCache(cacheName)) { CacheFactory = cacheFactory; }
private static void ConnectCache(string cacheName, DataCacheFactoryConfiguration config) { try { var factory = new DataCacheFactory(config); _cache = factory.GetCache(cacheName); _cache.CreateRegion(_cacheRegion); _cacheConnected.Set(); } catch { ; } }
public DataCache InicializeWithConfiguration() { DataCacheFactory _dataFactory = new DataCacheFactory(); DataCache _cache = _dataFactory.GetCache("default"); Debug.Assert(_cache != null); return _cache; }
//private static DataCacheFactory _factory; //private static bool _terminate = false; //static PopulateCacheService() //{ // _factory = new DataCacheFactory(); // //try // //{ // // _cache = factory.GetCache("default"); // //} // //catch (Exception ex) // //{ // // throw new FaultException<string>(ex.Message); // // //throw new FaultException(ex.Message); // //} // //Debug.Assert(_cache == null); //} private DataCache initDataCache() { try { if (_cache == null) { DataCacheFactory factory = new DataCacheFactory(); _cache = factory.GetCache("default"); } return _cache; } catch (Exception ex) { throw new Exception(ex.ToString()); } }