の分散データ構造 NCache

NCache 非常に高速でスケーラブルな .NET/ 用の分散キャッシュです。.NET Core、Java、Node.js、Python アプリケーション。 NCache アプリケーション データ キャッシュ、ASP.NET / ASP のために高トランザクション .NET サーバー アプリケーションによって使用されます。.NET Core セッション ストレージ、および Pub/Sub メッセージング。

NCache また、複数の .NET および Java アプリケーション間で共有される、非常に強力なインメモリ分散データストアにもなりました。 その結果、アプリケーションはますます多くの種類のデータを保存する必要があります。 NCache 複数のアプリケーション間で共有できます。 このニーズに応えるために、 NCache 複数のユーザー間で共有できる Java および .NET の分散データ構造を提供します。 彼らです:

これらのデータ構造のそれぞれについては、以下でさらに詳しく説明します。

 

分散キュー

分散キューを使用すると、分散環境で実行されている複数の .NET および Java アプリケーション間で共有するキューを作成できます。 また、キューは、データを入力した順序が確実に維持されるようにします。 また、キューからデータを取得するすべてのアプリケーションは、このシーケンスが常に正しいことを信頼できます。

string cacheName = "demoCache";
string QueueName = "DistributedQueue:Customers";
  
// Initialize an instance of the cache to begin performing operations:
ICache cache = NCache.Client.CacheManager.GetCache(cacheName);
  
// Creating a named distributed queue
IDistributedQueue<Customer> distQueue = 
cache.DataTypeManager.CreateQueue<Customer>(QueueName);
  
distQueue.Enqueue(new Customer {
	ContactName = "David Johnes", 
	CompanyName = "Lonesome Pine Restaurant"
});
String cacheName = "demoCache";
String queueName = "DistributedQueue:Customers";

// Initialize an instance of the cache to begin performing operations:
Cache cache = CacheManager.getCache(cacheName);

// Creating a named distributed queue
DistributedQueue<Customer> distQueue = cache.getDataStructuresManager().createQueue(queueName, Customer.class);

distQueue.add(new Customer("David Johnes", "Lonesome Pine Restaurant"));
distQueue.add(new Customer("Carlos Gonzalez", "LILA-Supermercado"));

上で見られるように、分散キューを使用すると、シーケンスに項目を追加 (エンキュー) できるため、後で同じシーケンス (FIFO) で項目を削除 (デキュー) できます。 分散キュー インターフェイスは次のとおりです。

public interface IDistributedQueue<T> : IEnumerable<T>, IEnumerable, ICollection,
IDistributedDataTypes, ILockable, INotifiable
{
	void Clear();
	bool Contains(T item);
	void CopyTo(T[] array, int arrayIndex);
	
	T Dequeue();
	void Enqueue(T item);
	T Peek();
	T[] ToArray();
}
public interface DistributedQueue<T> extends Queue<T>, DistributedDataStructure, Notifiable 
{
	void clear();
	void copyTo(T[] array, int arrayIndex);

	T peek();

	public interface Queue<E> extends Collection<E> {
		boolean add(E e);
		E remove();
	}

	public interface Collection<E> extends Iterable<E> {
		boolean contains(Object o);
	}
}

前述の IDistributedQueue インターフェイスでわかるように、これは従来のキュー機能をすべて提供します。

 

分散ハッシュセット

分散 HashSet は、.NET HashSet クラスと同様に動作しますが、複数のアプリケーションおよびユーザーに対して共有方法で動作します。 また、HashSet は次のようなすべての Set 操作を提供します。

  • - 重複はありません: セット内で
  • - セット操作: 和集合、交差、差分など

また、これは複数のアプリケーションまたはユーザーで共有される HashSet であるため、強力なデータ構造として使用できます。 ここではその使用方法の例を示します。

string cacheName = "demoCache";
string hashSetName = "DistributedHashSet:UniqueValueHashSet";

// Initialize an instance of the cache to begin performing operations:
ICache cache = NCache.Client.CacheManager.GetCache(cacheName);

// Creating distributed HashSet with absolute expiration
IDistributedHashSet<string> hashSet;
hashSet = cache.DataTypeManager.CreateHashSet<string>(hashSetName);

// Create data for HashSet
var daysOfWeek = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };

// Add multiple entries to the HashSet
hashSet.AddRange(daysOfWeek);

// Since this entry already exists, no change to the HashSet is made by this call
hashSet.Add("Monday");
String cacheName = "demoCache";
String hashSetName = "DistributedHashSet:UniqueValueHashSet";

// Initialize an instance of the cache to begin performing operations:
Cache cache = CacheManager.getCache(cacheName);

// Creating distributed HashSet with absolute expiration
DistributedHashSet<String> hashSet;
hashSet = cache.getDataStructuresManager().createHashSet(hashSetName, String.class);

// Add entries to the hashset
hashSet.add("Monday");
hashSet.add("Tuesday");
hashSet.add("Wednesday");
hashSet.add("Thursday");
hashSet.add("Friday");
hashSet.add("Saturday");
hashSet.add("Sunday");

// Since this entry already exists, no change to the hashset is made by this call
hashSet.add("Monday");

ご覧のとおり、XNUMX 回目に「月曜日」を追加すると、HashSet には追加されません。

 

分散辞書

分散ディクショナリ (IDistributedDictionary) は、通常の .NET IDictionary インターフェイスと同様に動作しますが、複数のアプリケーションおよびユーザーに対して共有方法で動作します。 また、分散辞書は、追加、更新、削除、含むなどのすべての辞書操作を提供します。

通常の辞書機能に加えて、分散辞書は、以下に基づいて項目を期限切れにする機能を提供します。 NCache のような有効期限オプション 絶対有効期限 & スライド式の有効期限.

ICache cache = NCache.Client.CacheManager.GetCache("demoCache");
string dictName = "DistributedDictionary:Customers";

IDistributedDictionary<string, Customer> dict = cache.DataTypeManager.GetDictionary<string, Customer>(dictName);

if (dict == null)
{
	DataTypeAttributes attributes = new DataTypeAttributes {
		Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0))
	};
	// Creating distributed Dictionary with absolute expiration of 1 minute
	dict = cache.DataTypeManager.CreateDictionary<string, Customer>(dictName, attributes);
}

Customer cust = new Customer
{	
	CustomerID = "customer1",
	ContactName = "David Johnes",
	CompanyName = "Lonesome Pine Restaurant",
	ContactNo = "(1) 408-354-9768",
	Address = "Silicon Valley, Santa Clara, California",
};
	   
dict.Add("customer1", cust);

Customer cachedCust;
bool fetched = dict.TryGetValue("customer1", out cachedCust);
String cacheName = "demoCache";
String dictName = "DistributedDictionary:Customers";
 
// Initialize an instance of the cache to begin performing operations:
Cache cache = CacheManager.getCache(cacheName);

DistributedMap<string, Customer> dict = cache.getDataStructuresManager().createMap(dictName, Customer.class);

Customer customer = new Customer("David Johnes", "Lonesome Pine Restaurant", "Customer1", "(1) 408-354-9768");

dict.put("customer1", customer);
Customer cachedCustomer = dict.get("customer1");

ご覧のとおり、分散ディクショナリは通常の .NET 分散 (IDictionary インターフェイス) と同様に動作します。 ただし、舞台裏では分散されているため、非常に拡張性が高くなります。 また、複数のアプリケーション間でも共有されます。

 

分散リスト

分散リストは通常​​の .NET IList と同様に動作しますが、分散され、複数のアプリケーションおよびプロセス間で共有できる点が異なります。 分散リストは並べ替えられていないリストであり、リストの最後に項目を追加できます。 追加 () メソッドまたは任意の場所で 入れる() インデックスを提供することによるメソッド。

以下は、分散リストの使用方法の例です。

ICache cache = NCache.Client.CacheManager.GetCache("demoCache");
string listName = "DistributedList:Customers";

IDistributedList<Customer> distList = cache.DataTypeManager.GetList<Customer>(listName);

if (distList == null)
{
	DataTypeAttributes attributes = new DataTypeAttributes {
		Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0))
	};

	// Creating Distributed List with absolute expiration of 1 minute
	distList = cache.DataTypeManager.CreateList<Customer>(listName, attributes);
}

Customer cust = new Customer
{
	CustomerID = "customer1",
	ContactName = "David Johnes",
	CompanyName = "Lonesome Pine Restaurant",
	ContactNo = "(1) 408-354-9768",
	Address = "Silicon Valley, Santa Clara, California",
};

distList.Add(cust);
Customer cachedCustomer = distList[0];
String cacheName = "demoCache";
String listName = "DistributedList:Customers";

// Initialize an instance of the cache to begin performing operations:
Cache cache = CacheManager.getCache(cacheName);

DistributedList distributedList = cache.getDataStructuresManager().createList(listName,   Customer.class);

Customer customer = new Customer("David Johnes", "Lonesome Pine Restaurant", "Customer1", "(1) 408-354-9768");

distributedList.add(customer);
Customer cachedCustomer = (Customer) distributedList.get(0);

リストから項目を削除したり、リストを反復処理したり、その他の多くの操作を実行したりすることもできます。

 

分散カウンター

分散カウンターは、次の強力なデータ構造です。 NCache これにより、複数のアプリケーションで共有される分散環境で一意のカウンターを維持できるようになります。 これには多くの用途があり、これを使用してアプリケーションを迅速に開発できます。 以下に例を示します。

ICache cache = NCache.Client.CacheManager.GetCache("demoCache");
string counterName = "DistributedCounter:Customers";

ICounter counter = cache.DataTypeManager.GetCounter(counterName);
if (counter == null)
{
	DataTypeAttributes attributes = new DataTypeAttributes {
		Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0))
	};
			
	// Creating Distributed Counter with absolute expiration to modify cache properties of the Counter, provide an instance of DataTypeAttributes in the second parameter
	counter = cache.DataTypeManager.CreateCounter(counterName, attributes);
}

counter.SetValue(1000);
long newValue = counter.IncrementBy(5);
newValue = counter.Value;
newValue = counter.DecrementBy(2);
String cacheName = "demoCache";
String counterName = "DistributedCounter:Customers";

// Initialize an instance of the cache to begin performing operations:
Cache cache = CacheManager.getCache(cacheName);

Counter counter = cache.getDataStructuresManager().createCounter(counterName);
counter.setValue(1000);
long newValue = counter.incrementBy(5);
newValue = counter.getValue();
newValue = counter.decrementBy(2);

次はどうする?

NCache ドキュメント
エディションの比較
パーソナライズされたLIVEデモをリクエストする
ダウンロード NCache

お問い合わせ(英語)

電話
©著作権 Alachisoft 2002 - . All rights reserved. NCache はダイヤテック株式会社の登録商標です。