You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2016/11/18 09:56:15 UTC
ignite git commit: IGNITE-4129 .NET: Add NearCacheExample
Repository: ignite
Updated Branches:
refs/heads/master 4672b33ff -> 82e2501ca
IGNITE-4129 .NET: Add NearCacheExample
This closes #1245
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/82e2501c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/82e2501c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/82e2501c
Branch: refs/heads/master
Commit: 82e2501ca3eb0309992ea69dedafad9592e59765
Parents: 4672b33
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Fri Nov 18 12:56:05 2016 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Fri Nov 18 12:56:05 2016 +0300
----------------------------------------------------------------------
.../Examples/ExamplesTest.cs | 2 +-
.../Apache.Ignite.Examples.csproj | 1 +
.../Datagrid/NearCacheExample.cs | 87 ++++++++++++++++++++
3 files changed, 89 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/82e2501c/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
index 064b110..112db21 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
@@ -143,7 +143,7 @@ namespace Apache.Ignite.Core.Tests.Examples
// ReSharper disable once MemberCanBeMadeStatic.Global
public IEnumerable<Example> TestCasesLocal
{
- get { return Example.GetExamples(); }
+ get { return Example.GetExamples().Where(x => x.Name != "NearCacheExample"); }
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/82e2501c/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
index 44e1bc2..332d3a1 100644
--- a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
@@ -53,6 +53,7 @@
<Compile Include="Datagrid\ContinuousQueryExample.cs" />
<Compile Include="Datagrid\DataStreamerExample.cs" />
<Compile Include="Datagrid\EntryProcessorExample.cs" />
+ <Compile Include="Datagrid\NearCacheExample.cs" />
<Compile Include="Datagrid\OptimisticTransactionExample.cs" />
<Compile Include="Datagrid\PutGetExample.cs" />
<Compile Include="Datagrid\LinqExample.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/82e2501c/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/NearCacheExample.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/NearCacheExample.cs b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/NearCacheExample.cs
new file mode 100644
index 0000000..1c18256
--- /dev/null
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/NearCacheExample.cs
@@ -0,0 +1,87 @@
+\ufeff/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Examples.Datagrid
+{
+ using System;
+ using Apache.Ignite.Core;
+ using Apache.Ignite.Core.Cache;
+ using Apache.Ignite.Core.Cache.Configuration;
+ using Apache.Ignite.Core.Cache.Eviction;
+
+ /// <summary>
+ /// Example demonstrates the usage of a near cache on an Ignite client node side.
+ /// <para />
+ /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build).
+ /// Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration} folder.
+ /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties ->
+ /// Application -> Startup object);
+ /// 3) Start example (F5 or Ctrl+F5).
+ /// <para />
+ /// This example must be run with standalone Apache Ignite.NET node:
+ /// 1) Run %IGNITE_HOME%/platforms/dotnet/bin/Apache.Ignite.exe:
+ /// Apache.Ignite.exe -configFileName=platforms\dotnet\examples\apache.ignite.examples\app.config
+ /// 2) Start example.
+ /// </summary>
+ public class NearCacheExample
+ {
+ private const string CacheName = "dotnet_near_cache_example";
+
+ [STAThread]
+ public static void Main()
+ {
+ // Make sure to start an Ignite server node before.
+ Ignition.ClientMode = true;
+
+ using (var ignite = Ignition.StartFromApplicationConfiguration())
+ {
+ Console.WriteLine(">>> Client node connected to the cluster");
+
+ // Creating a distributed and near cache.
+ var nearCacheCfg = new NearCacheConfiguration
+ {
+ EvictionPolicy = new LruEvictionPolicy
+ {
+ // Near cache will store only 10 recently accessed/used entries.
+ MaxSize = 10
+ }
+ };
+
+ Console.WriteLine(">>> Populating the cache...");
+
+ ICache<int, int> cache = ignite.GetOrCreateCache<int, int>(
+ new CacheConfiguration(CacheName), nearCacheCfg);
+
+ // Adding data into the cache.
+ // Latest 10 entries will be stored in the near cache on the client node side.
+ for (int i = 0; i < 1000; i++)
+ cache.Put(i, i * 10);
+
+ Console.WriteLine(">>> Cache size: [Total={0}, Near={1}]",
+ cache.GetSize(), cache.GetSize(CachePeekMode.Near));
+
+ Console.WriteLine("\n>>> Reading from near cache...");
+
+ foreach (var entry in cache.GetLocalEntries(CachePeekMode.Near))
+ Console.WriteLine(entry);
+
+ Console.WriteLine("\n>>> Example finished, press any key to exit ...");
+ Console.ReadKey();
+ }
+ }
+ }
+}