의 분산 데이터 구조 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"));

위에서 볼 수 있듯이 Distributed Queue를 사용하면 시퀀스에 항목을 추가(Enqueue)하여 나중에 동일한 시퀀스(FIFO)에서 항목을 제거(Dequeue)할 수 있습니다. 분산 대기열 인터페이스는 다음과 같습니다.

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 인터페이스에서 볼 수 있듯이 이는 모든 기존 대기열 기능을 제공합니다.

 

분산 해시 세트

Distributed 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");

보시다시피 "Monday"를 두 번째로 추가하면 HashSet에 추가되지 않습니다.

 

분산 사전

분산 사전(IDistributedDictionary)은 일반 .NET IDictionary 인터페이스처럼 작동하지만 여러 애플리케이션 및 사용자에 대해 공유 방식으로 작동합니다. 또한 분산 사전은 추가, 업데이트, 제거, 포함 등과 같은 모든 사전 작업을 제공합니다.

일반 사전 기능 외에도 Distributed Dictionary는 다음을 기반으로 항목을 만료하는 기능을 제공합니다. 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");

보시다시피 Distributed Dictionary는 일반 .NET Distributed(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);

목록에서 항목을 제거하고, 반복하고, 기타 여러 작업을 수행할 수도 있습니다.

 

분산 카운터

Distributed Counter는 강력한 데이터 구조입니다. 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 기술 문서
판 비교
맞춤형 라이브 데모 요청
다운로드 NCache
© 저작권 Alachisoft 2002 - . 판권 소유. NCache 는 Diyatech Corp.의 등록상표입니다.