private static void PopulateCache(ICacheClient <int, Organization> cache) { cache.Put(1, new Organization( "Apache", new Address("1065 East Hillsdale Blvd, Foster City, CA", 94404), OrganizationType.Private, DateTime.Now)); cache.Put(2, new Organization("Microsoft", new Address("1096 Eddy Street, San Francisco, CA", 94109), OrganizationType.Private, DateTime.Now)); }
/// <summary> /// Initializes account balance. /// </summary> private static void InitAccounts(ICacheClient <int, Account> cache) { // Clean up caches on all nodes before run. cache.Clear(); // Initialize. cache.Put(1, new Account(1, 100)); cache.Put(2, new Account(2, 200)); Console.WriteLine(); Console.WriteLine(">>> Accounts before transfer: "); Console.WriteLine(">>> " + cache.Get(1)); Console.WriteLine(">>> " + cache.Get(2)); Console.WriteLine(); }
/// <summary> /// Execute individual Put and Get, getting value in binary format, without de-serializing it. /// </summary> /// <param name="ignite">Ignite instance.</param> private static void PutGetBinary(IIgniteClient ignite) { ICacheClient <int, Organization> cache = ignite.GetCache <int, Organization>(CacheName); // Create new Organization to store in cache. Organization org = new Organization( "Microsoft", new Address("1096 Eddy Street, San Francisco, CA", 94109), OrganizationType.Private, DateTime.Now ); // Put created data entry to cache. cache.Put(1, org); // Create projection that will get values as binary objects. var binaryCache = cache.WithKeepBinary <int, IBinaryObject>(); // Get recently created organization as a binary object. var binaryOrg = binaryCache.Get(1); // Get organization's name from binary object (note that object doesn't need to be fully deserialized). string name = binaryOrg.GetField <string>("name"); Console.WriteLine(); Console.WriteLine(">>> Retrieved organization name from binary object: " + name); }
public void PopulateEmployees() { List <Employee> messages = new List <Employee> { new Employee { Name = "abc", Salary = 100, EmpId = "1" }, new Employee { Name = "abc-1", Salary = 200, EmpId = "2" }, new Employee { Name = "abc-2", Salary = 400, EmpId = "3" }, new Employee { Name = "abc-3", Salary = 300, EmpId = "4" }, new Employee { Name = "abc-4", Salary = 200, EmpId = "5" }, }; ICacheClient <string, Employee> cache = null; foreach (var mess in messages) { using (IIgniteClient client = Ignition.StartClient(this._igniteClientConfiguration)) { //get cache configuraation cache = client.GetOrCreateCache <string, Employee>(GetOrCreateEmployeeCacheConfig("Employees")); cache.Put(mess.EmpId, mess); Console.WriteLine(cache.Get(mess.EmpId).Name); } } }
/// <summary> /// Populates the cache with employee data. /// </summary> public static void PopulateCache(ICacheClient <int, Employee> cache) { var id = 0; foreach (var employee in GetSampleEmployees()) { cache.Put(id++, employee); } }
/** <inheritDoc /> */ protected override void OnStarted() { base.OnStarted(); _cache = GetClient().GetCache <int, Employee>(CacheName); for (int i = 0; i < Emps.Length; i++) { _cache.Put(i, Emps[i]); } }
public void Put() { var idxA = _random.Next(0, _max); var idxB = _random.Next(0, _max); var idxC = _random.Next(0, _max); var idxD = _random.Next(0, _max); var idxE = _random.Next(0, _max); _cacheA.Put(idxA, _modelsA[idxA]); _cacheB.Put(idxB, _modelsB[idxB]); _cacheC.Put(idxC, _modelsC[idxC]); _cacheD.Put(idxD, _modelsD[idxD]); _cacheE.Put(idxE, _modelsE[idxE]); }
/** <inheritDoc /> */ protected override void OnStarted() { Dataset = 1000; base.OnStarted(); Cache = GetClient().GetOrCreateCache <int, Doubles>(CacheName); var array = Doubles.GetInstances(Dataset); for (int i = 0; i < array.Length; i++) { Cache.Put(i, array[i]); } }
/// <summary> /// Populate cache with data for this example. /// </summary> /// <param name="cache">Cache.</param> private static void PopulateCache(ICacheClient <int, Employee> cache) { cache.Put(1, new Employee( "James Wilson", 12500, new Address("1096 Eddy Street, San Francisco, CA", 94109), new[] { "Human Resources", "Customer Service" }, 1)); cache.Put(2, new Employee( "Daniel Adams", 11000, new Address("184 Fidler Drive, San Antonio, TX", 78130), new[] { "Development", "QA" }, 1)); cache.Put(3, new Employee( "Cristian Moss", 12500, new Address("667 Jerry Dove Drive, Florence, SC", 29501), new[] { "Logistics" }, 1)); cache.Put(4, new Employee( "Allison Mathis", 25300, new Address("2702 Freedom Lane, San Francisco, CA", 94109), new[] { "Development" }, 2)); cache.Put(5, new Employee( "Breana Robbin", 6500, new Address("3960 Sundown Lane, Austin, TX", 78130), new[] { "Sales" }, 2)); cache.Put(6, new Employee( "Philip Horsley", 19800, new Address("2803 Elsie Drive, Sioux Falls, SD", 57104), new[] { "Sales" }, 2)); cache.Put(7, new Employee( "Brian Peters", 10600, new Address("1407 Pearlman Avenue, Boston, MA", 12110), new[] { "Development", "QA" }, 2)); }
public void PutWithAffinity() { var idxA = _random.Next(0, _max); var idxB = _random.Next(0, _max); var idxC = _random.Next(0, _max); var idxD = _random.Next(0, _max); var idxE = _random.Next(0, _max); var aff = _random.Next(0, _max); _cacheF.Put(new AffinityKey(idxA, aff), _modelsA[idxA]); _cacheG.Put(new AffinityKey(idxB, aff), _modelsB[idxB]); _cacheH.Put(new AffinityKey(idxC, aff), _modelsC[idxC]); _cacheI.Put(new AffinityKey(idxD, aff), _modelsD[idxD]); _cacheJ.Put(new AffinityKey(idxE, aff), _modelsE[idxE]); }
public static void Main() { Ignition.Start(); var cfg = new IgniteClientConfiguration { Host = "192.168.1.35" }; using (IIgniteClient client = Ignition.StartClient(cfg)) { ICacheClient <int, string> cache = client.GetCache <int, string>("cache"); cache.Put(1, "Hello, World!"); } Console.ReadKey(); }
public void AllKeyBasedOperations_PrimitiveKeyType_RequestIsRoutedToPrimaryNode(int key, int gridIdx) { int unused; TestOperation(() => _cache.Get(key), gridIdx); TestAsyncOperation(() => _cache.GetAsync(key), gridIdx); TestOperation(() => _cache.TryGet(key, out unused), gridIdx); TestAsyncOperation(() => _cache.TryGetAsync(key), gridIdx); TestOperation(() => _cache.Put(key, key), gridIdx, "Put"); TestAsyncOperation(() => _cache.PutAsync(key, key), gridIdx, "Put"); TestOperation(() => _cache.PutIfAbsent(key, key), gridIdx, "PutIfAbsent"); TestAsyncOperation(() => _cache.PutIfAbsentAsync(key, key), gridIdx, "PutIfAbsent"); TestOperation(() => _cache.GetAndPutIfAbsent(key, key), gridIdx, "GetAndPutIfAbsent"); TestAsyncOperation(() => _cache.GetAndPutIfAbsentAsync(key, key), gridIdx, "GetAndPutIfAbsent"); TestOperation(() => _cache.Clear(key), gridIdx, "ClearKey"); TestAsyncOperation(() => _cache.ClearAsync(key), gridIdx, "ClearKey"); TestOperation(() => _cache.ContainsKey(key), gridIdx, "ContainsKey"); TestAsyncOperation(() => _cache.ContainsKeyAsync(key), gridIdx, "ContainsKey"); TestOperation(() => _cache.GetAndPut(key, key), gridIdx, "GetAndPut"); TestAsyncOperation(() => _cache.GetAndPutAsync(key, key), gridIdx, "GetAndPut"); TestOperation(() => _cache.GetAndReplace(key, key), gridIdx, "GetAndReplace"); TestAsyncOperation(() => _cache.GetAndReplaceAsync(key, key), gridIdx, "GetAndReplace"); TestOperation(() => _cache.GetAndRemove(key), gridIdx, "GetAndRemove"); TestAsyncOperation(() => _cache.GetAndRemoveAsync(key), gridIdx, "GetAndRemove"); TestOperation(() => _cache.Replace(key, key), gridIdx, "Replace"); TestAsyncOperation(() => _cache.ReplaceAsync(key, key), gridIdx, "Replace"); TestOperation(() => _cache.Replace(key, key, key + 1), gridIdx, "ReplaceIfEquals"); TestAsyncOperation(() => _cache.ReplaceAsync(key, key, key + 1), gridIdx, "ReplaceIfEquals"); TestOperation(() => _cache.Remove(key), gridIdx, "RemoveKey"); TestAsyncOperation(() => _cache.RemoveAsync(key), gridIdx, "RemoveKey"); TestOperation(() => _cache.Remove(key, key), gridIdx, "RemoveIfEquals"); TestAsyncOperation(() => _cache.RemoveAsync(key, key), gridIdx, "RemoveIfEquals"); }
/// <summary> /// Puts the invocation response in the specified cache. /// </summary> /// <param name="invocation"></param> /// <param name="cacheClient"></param> /// <param name="cacheKey"></param> /// <param name="region"></param> /// <param name="directive"></param> protected static void PutResponseInCache(IInvocation invocation, ICacheClient cacheClient, string cacheKey, string region, ResponseCachingDirective directive) { // bail if the directive does not tell us to cache anything if (directive == null || !directive.EnableCaching || directive.TimeToLive == TimeSpan.Zero) { return; } // if we don't have a cache key, this is an error if (cacheKey == null) { throw new InvalidOperationException( string.Format("{0} is cacheable but the request class does not implement IDefinesCacheKey.", invocation.GetType().FullName)); } // put response in cache cacheClient.Put(cacheKey, invocation.ReturnValue, new CachePutOptions(region, directive.TimeToLive, false)); }
/// <summary> /// Execute individual Put and Get. /// </summary> /// <param name="cache">Cache instance.</param> private static void PutGet(ICacheClient <int, Organization> cache) { // Create new Organization to store in cache. Organization org = new Organization( "Microsoft", new Address("1096 Eddy Street, San Francisco, CA", 94109), OrganizationType.Private, DateTime.Now ); // Put created data entry to cache. cache.Put(1, org); // Get recently created employee as a strongly-typed fully de-serialized instance. Organization orgFromCache = cache.Get(1); Console.WriteLine(); Console.WriteLine(">>> Retrieved organization instance from cache: " + orgFromCache); }
/// <summary> /// Start new node, create new user with given credentials and try to authenticate. /// </summary> /// <param name="user">Username</param> /// <param name="pass">Password</param> private void CreateNewUserAndAuthenticate(string user, string pass) { using (var srv = Ignition.Start(SecureServerConfig())) { srv.GetCluster().SetActive(true); using (var cli = Ignition.StartClient(GetSecureClientConfig())) { CacheClientConfiguration ccfg = new CacheClientConfiguration { Name = "TestCache", QueryEntities = new[] { new QueryEntity { KeyType = typeof(string), ValueType = typeof(string), }, }, }; ICacheClient <string, string> cache = cli.GetOrCreateCache <string, string>(ccfg); cache.Put("key1", "val1"); cache.Query(new SqlFieldsQuery("CREATE USER \"" + user + "\" WITH PASSWORD '" + pass + "'")).GetAll(); } var cliCfg = GetSecureClientConfig(); cliCfg.UserName = user; cliCfg.Password = pass; using (var cli = Ignition.StartClient(cliCfg)) { ICacheClient <string, string> cache = cli.GetCache <string, string>("TestCache"); string val = cache.Get("key1"); Assert.True(val == "val1"); } } }
public void TestAuthentication() { using (var srv = Ignition.Start(SecureServerConfig())) { srv.GetCluster().SetActive(true); using (var cli = Ignition.StartClient(SecureClientConfig())) { CacheClientConfiguration ccfg = new CacheClientConfiguration() { Name = "TestCache", QueryEntities = new[] { new QueryEntity { KeyType = typeof(string), ValueType = typeof(string), }, }, }; ICacheClient <string, string> cache = cli.GetOrCreateCache <string, string>(ccfg); cache.Put("key1", "val1"); cache.Query(new SqlFieldsQuery("CREATE USER \"my_User\" WITH PASSWORD 'my_Password'")).GetAll(); } var cliCfg = SecureClientConfig(); cliCfg.UserName = "******"; cliCfg.Password = "******"; using (var cli = Ignition.StartClient(cliCfg)) { ICacheClient <string, string> cache = cli.GetCache <string, string>("TestCache"); string val = cache.Get("key1"); Assert.True(val == "val1"); } } }
/// <summary> /// Puts the invocation response in the specified cache. /// </summary> /// <param name="invocation"></param> /// <param name="cacheClient"></param> /// <param name="request"> </param> /// <param name="region"></param> /// <param name="directive"></param> protected static void PutResponseInCache(IInvocation invocation, object request, ICacheClient cacheClient, string region, ResponseCachingDirective directive) { // bail if the directive does not tell us to cache anything if (directive == null || !directive.EnableCaching || directive.TimeToLive == TimeSpan.Zero) { return; } var strategy = ResponseDataCachingStrategy.Get(invocation.Method); var data = strategy.GetCacheDataToPut(request, invocation.ReturnValue); if (data == null || data.Length == 0) { throw new InvalidOperationException( string.Format("{0} is cacheable but the caching strategy didn't return any data to put in the cache.", invocation.GetType().FullName)); } foreach (var item in data) { cacheClient.Put(item.CacheKey, item.Data, new CachePutOptions(region, directive.TimeToLive, false)); } }
/// <summary> /// Update or insert an object /// </summary> /// <param name="item"></param> /// <param name="excludedFromEviction">In cache-only mode,if tue the item is never evicted from the cache</param> public void Put(T item, bool excludedFromEviction = false) { _client.Put(item, excludedFromEviction); }
/// <summary> /// Create the database of estate agency. /// Requires connection to the cluster. /// </summary> /// <returns>True if database was successfully created.</returns> public static bool CreateDatabase() { if (client == null) { return(false); } // Cache configuration goes here ---------------------------------- CacheClientConfiguration credentialCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "credential", AtomicityMode = CacheAtomicityMode.Transactional /* * QueryEntities = new[] * { * new QueryEntity * { * TableName = "Credentials", * KeyType = typeof(string), * ValueType = typeof(Credential) * } * } */ }; CacheClientConfiguration personCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "person", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "Persons", KeyType = typeof(int), ValueType = typeof(Person) } } }; CacheClientConfiguration agentCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "agent", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "Agents", KeyType = typeof(int), ValueType = typeof(Agent) } } }; CacheClientConfiguration estateobjectCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "estateobject", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "EstateObjects", KeyType = typeof(int), ValueType = typeof(EstateObject) }, new QueryEntity { TableName = "Houses", KeyType = typeof(int), ValueType = typeof(House) }, new QueryEntity { TableName = "Flats", KeyType = typeof(int), ValueType = typeof(Flat) }, new QueryEntity { TableName = "Landplots", KeyType = typeof(int), ValueType = typeof(Landplot) }, } }; CacheClientConfiguration locationCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "location", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "Locations", KeyType = typeof(int), ValueType = typeof(Location) } } }; CacheClientConfiguration clientwishCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "clientwish", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "ClientWishes", KeyType = typeof(int), ValueType = typeof(ClientWish) } } }; CacheClientConfiguration bookmarkCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "bookmark", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "Bookmarks", KeyType = typeof(long), ValueType = typeof(Bookmark), Indexes = new QueryIndex[] { new QueryIndex("PersonID"), new QueryIndex("ObjectID") } } } }; CacheClientConfiguration matchCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "match", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "Matches", KeyType = typeof(long), ValueType = typeof(Match) } } }; CacheClientConfiguration orderCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "order", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "Orders", KeyType = typeof(long), ValueType = typeof(Match) } } }; CacheClientConfiguration dealCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "deal", AtomicityMode = CacheAtomicityMode.Transactional, QueryEntities = new[] { new QueryEntity { TableName = "Deals", KeyType = typeof(int), ValueType = typeof(Deal) } } }; CacheClientConfiguration lastusedkeyCfg = new CacheClientConfiguration { GroupName = "estateagency", Name = "lastusedkey", AtomicityMode = CacheAtomicityMode.Transactional }; // Cache creation goes here --------------------------------------- LocationCache = client.CreateCache <int, Location> (locationCfg); CredentialCache = client.CreateCache <string, Credential> (credentialCfg); PersonCache = client.CreateCache <int, Person> (personCfg); AgentCache = client.CreateCache <int, Agent> (agentCfg); ObjectCache = client.CreateCache <int, EstateObject> (estateobjectCfg); HouseCache = client.GetCache <int, House> ("estateobject"); FlatCache = client.GetCache <int, Flat> ("estateobject"); LandplotCache = client.GetCache <int, Landplot> ("estateobject"); ClientWishCache = client.CreateCache <int, ClientWish> (clientwishCfg); MatchCache = client.CreateCache <long, Match> (matchCfg); BookmarkCache = client.CreateCache <long, Bookmark> (bookmarkCfg); OrderCache = client.CreateCache <long, Order> (orderCfg); DealCache = client.CreateCache <int, Deal> (dealCfg); LastUsedKeys = Client.CreateCache <string, int> (lastusedkeyCfg); foreach (string i in CacheIndependentIntKeyNames) { LastUsedKeys.Put(i, 0); } return(true); }
public void PutBinary() { var idx = Random.Next(0, Params.Instance.Value.TotalObjects); _binaryCache.Put(idx, _binaryModels[idx]); }
public void PutPrimitive() { _cache.Put(1, 1); }
public void Put(string key, object value, CachePutOptions options) { _cacheClient.Put(key, value, options); LogPut(key, value, options); }
/// <summary> /// Cache put. /// </summary> private void Put(BenchmarkState state) { int idx = BenchmarkUtils.GetRandomInt(Dataset); _cache.Put(idx, Emps[idx]); }
/// <summary> /// Puts the invocation response in the specified cache. /// </summary> /// <param name="invocation"></param> /// <param name="cacheClient"></param> /// <param name="request"> </param> /// <param name="region"></param> /// <param name="directive"></param> protected static void PutResponseInCache(IInvocation invocation, object request, ICacheClient cacheClient, string region, ResponseCachingDirective directive) { // bail if the directive does not tell us to cache anything if (directive == null || !directive.EnableCaching || directive.TimeToLive == TimeSpan.Zero) return; var strategy = ResponseDataCachingStrategy.Get(invocation.Method); var data = strategy.GetCacheDataToPut(request, invocation.ReturnValue); if (data == null || data.Length == 0) { throw new InvalidOperationException( string.Format("{0} is cacheable but the caching strategy didn't return any data to put in the cache.", invocation.GetType().FullName)); } foreach (var item in data) cacheClient.Put(item.CacheKey, item.Data, new CachePutOptions(region, directive.TimeToLive, false)); }
/// <summary> /// Update or insert an object /// </summary> /// <param name="item"></param> public void Put(T item) { _client.Put(item); }
/// <summary> /// Puts the invocation response in the specified cache. /// </summary> /// <param name="invocation"></param> /// <param name="cacheClient"></param> /// <param name="cacheKey"></param> /// <param name="region"></param> /// <param name="directive"></param> protected static void PutResponseInCache(IInvocation invocation, ICacheClient cacheClient, string cacheKey, string region, ResponseCachingDirective directive) { // bail if the directive does not tell us to cache anything if (directive == null || !directive.EnableCaching || directive.TimeToLive == TimeSpan.Zero) return; // if we don't have a cache key, this is an error if (cacheKey == null) throw new InvalidOperationException( string.Format("{0} is cacheable but the request class does not implement IDefinesCacheKey.", invocation.GetType().FullName)); // put response in cache cacheClient.Put(cacheKey, invocation.ReturnValue, new CachePutOptions(region, directive.TimeToLive, false)); }