효율적인 데이터 관리를 위해서는 특정 속성을 기반으로 애플리케이션 데이터를 신속하게 검색할 수 있는 기능이 필요합니다. 데이터 양이 증가함에 따라 이러한 필요성이 더욱 중요해집니다. 일반적으로 데이터베이스에는 데이터 분류를 용이하게 하는 필드가 이미 있으며 이러한 필드는 데이터를 캐싱할 때 인덱스로 사용할 수 있습니다. 그러나 태그 또는 기타 사용자 정의 속성과 같이 캐시에 없는 속성을 기반으로 데이터를 그룹화하려는 경우가 있을 수 있습니다.
와 NCache, 사용자 정의 속성을 기반으로 애플리케이션 데이터를 분류할 수 있을 뿐만 아니라 이러한 속성을 기반으로 검색을 수행할 수도 있습니다. 기존 인덱싱 외에도 NCache 다음을 사용하여 데이터를 분류하는 옵션을 제공합니다. 그룹, 태그및 명명된 태그, 데이터 분류 및 검색에서 더 큰 유연성을 허용합니다.
그룹을 통한 캐시 데이터 분류
캐시되고 그룹 이름으로 식별할 수 있는 항목 모음의 경우 그룹을 만들 수 있습니다. 이 이름은 그룹과 관련된 모든 항목을 검색하는 데 도움이 될 수 있습니다. 예를 들어 특정 고객 또는 특정 제품 범주와 관련된 모든 제품으로 그룹을 만들 수 있습니다. 단순히 이름을 부르면 NCache 관련된 모든 캐시된 항목을 반환합니다. 단일 그룹과 연결된 단일 항목만 있을 수 있습니다. 아래에 제공된 예는 다른 지역(이 경우 동부 해안)의 고객이 온라인 상점에서 어떻게 그룹화되는지 보여줍니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
// Pre-conditions: Cache is already connected. // Create a unique cache key for this customer. string customerKey = $"Customer:ALFKI"; // Get customer from cache Customer customer = cache.Get<Customer>(customerKey); // Get customer from database if not found in cache if (customer == null) { customer = FetchCustomerFromDB("ALFKI"); // Create a new CacheItem var cacheItem = new CacheItem(customer); // Specify the group cacheItem.Group = "East Coast Customers"; // Add customer object to cache with group cache.Add(customerKey, cacheItem); } |
$Group$ 키워드를 사용하여 그룹에 포함된 캐시 객체를 검색하기 위해 SQL 쿼리를 사용할 수 있습니다. 다음 코드 예제는 SQL 쿼리를 사용하여 특정 지역(이 경우 West Coast)의 모든 고객을 보는 방법을 보여줍니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
// Pre-conditions: Items with groups exist in the cache // Custom class is query indexed through the NCache Manager or config.ncconf // Create an SQL Query with the specified criteria // Make sure to use the Fully Qualified Name (FQN) string query = "SELECT CustomerID,ContactName FROM Alachisoft.NCache.Samples.Data.Customer WHERE $Group$ = ? "; // Use QueryCommand for query execution var queryCommand = new QueryCommand(query); // Providing parameters for query queryCommand.Parameters.Add("$Group$", "West Coast Customers"); // Executing the Query ICacheReader reader = cache.SearchService.ExecuteReader(queryCommand); // Read results if result set is not empty if (reader.FieldCount > 0) { while (reader.Read()) { // Get the value of the result set string customerID = reader.GetValue<string>("CustomerID"); string customerName = reader.GetValue<string>("ContactName"); Console.WriteLine($"Customer '{customerName}' having ID '{customerID}' belongs to West Coast."); } } else { Console.WriteLine($"No customers from West Coast found"); } |
효율성을 높이는 것 외에도 그룹은 사용자가 검색 or 삭제 애플리케이션의 확장성을 높이는 이러한 논리적 범주를 기반으로 하는 데이터입니다. 또한 그룹은 특정 검색 기준과 일치하는 일반적으로 사용되는 데이터를 캐시하여 데이터베이스 검색을 반복적으로 실행하는 비용을 피할 수 있습니다.
태그를 통한 캐시 데이터 분류
태그 in NCache 여러 태그를 사용하여 캐시된 항목을 분류하는 방법을 제공합니다. 캐시된 개체에는 항목을 검색하는 데 사용할 수 있는 하나 이상의 태그가 할당될 수 있습니다. 예를 들어 지역, 언어 또는 제품 기능에 따라 항목을 분류할 수 있습니다. 태그의 이름을 호출하면 NCache 해당 태그가 있고 캐시된 모든 항목을 반환합니다. 태그를 사용하면 메타데이터를 캐시된 개체에 연결하여 검색 및 데이터 조작을 쉽게 할 수 있습니다. 다음 예는 동부 해안 지역에서 로그인한 고객이 캐시에 추가되는 방법을 보여줍니다.
1 2 3 4 5 6 7 8 9 10 11 |
// Create an array of tags assigned to customer Tag[] tags = new Tag[2]; tags[0] = new Tag("East Coast Customers"); tags[1] = new Tag("VIP Customers"); // Setting the tag property of the cacheItem cacheItem.Tags = tags; cache.Add(customerKey, cacheItem); // CacheItem added successfully |
마찬가지로 특정 태그 키워드 $Tag$가 있는 항목을 쿼리할 수 있습니다. 아래 예의 SQL 쿼리는 태그에 연결된 모든 항목을 반환합니다. VIP 고객.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
// Create a query for search string query = "Select CustomerID,ContactName FROM Alachisoft.NCache.Samples.Data.Customer WHERE $Tag$ = ?"; // Use QueryCommand for query execution var queryCommand = new QueryCommand(query); queryCommand.Parameters.Add("$Tag$", "VIP Customers"); // Executing Query ICacheReader reader = cache.SearchService.ExecuteReader(queryCommand); // Read results if result set is not empty if (reader.FieldCount > 0) { while (reader.Read()) { // Get the value of the result set string customerID = reader.GetValue<string> ("CustomerID"); string contactName = reader.GetValue<string>("ContactName"); Console.WriteLine($"Customer '{contactName}' having ID '{customerID}' is a VIP Customer."); } } else { Console.WriteLine($"No VIP Customers found"); } |
태그를 사용하면 사용자에게 각 특정 유형과 높은 수준의 관련성을 제공합니다. 태그에서 제공하는 다른 CRUD 작업을 알아보려면 다음을 참조하십시오. NCache 선적 서류 비치.
명명된 태그를 통한 캐시 데이터 분류
캐시된 개체에는 항목을 검색하는 데 사용할 수 있는 목록을 통해 여러 개의 명명된 태그가 제공될 수 있습니다. 각 명명된 태그에는 태그의 이름을 나타내는 문자열인 키와 기본 유형인 값의 두 가지 매개 변수가 있습니다. 예를 들어 가격 범위 또는 가용성에 따라 항목에 명명된 태그를 할당할 수 있습니다. 태그 이름과 값을 호출하면 NCache 해당 태그가 있는 모든 항목을 가져와야 하는 경우 지정된 명명된 태그가 있는 모든 저장된 항목을 반환합니다.
그룹 및 태그와 마찬가지로 다음을 수행할 수 있습니다. 항목 검색 개체 쿼리를 사용하여 명명된 태그가 있는 캐시에서. 특정 Named Tag가 이미 캐시의 항목에 추가된 경우, NCache 사용자에게 이러한 명명된 태그를 업데이트할 수 있는 기회를 제공합니다. 사용 NCache의 사용자 정의 클래스, 즉 CacheItem, 캐시에 데이터를 추가할 수 있습니다. 재산으로는 명명된 태그 클래스, CacheItem을 사용하면 항목과 관련된 추가 사양을 추가로 지정할 수 있습니다. 아래 예시에서는 VIP 멤버십(VIP 멤버는 10% 할인)을 보유한 고객을 CacheItem의 속성으로 지정하여 Named Tags를 설정합니다.
1 2 3 4 5 6 7 8 9 |
// Creating a Named Tags Dictionary var namedTags = new NamedTagsDictionary(); // Adding Named Tags to the Dictionary where Keys are the names of the tags as string type and Values are of primitive type namedTags.Add("VIP_Membership_Discount", 0.10); // Setting the named tag property of the cacheItem cacheItem.NamedTags = namedTags; cache.Add(customerKey, cacheItem); |
항목이 있을 때 명명된 태그와 함께 캐시에 추가됨, SQL 쿼리를 통해 쉽게 검색할 수 있습니다. 다음 예에서 사용자는 12% VIP 멤버십 할인이 있는 모든 고객을 보고자 합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// Create an SQL Query with the specified criteria string query = "SELECT CustomerID,ContactName FROM Alachisoft.NCache.Samples.Data.Customer WHERE VIP_Membership_Discount = 0.12 "; // Use QueryCommand for query execution var queryCommand = new QueryCommand(query); // Executing the Query ICacheReader reader = cache.SearchService.ExecuteReader(queryCommand); // Read results if the result set is not empty if (reader.FieldCount > 0) { while (reader.Read()) { // Get the value of the result set string customerID = reader.GetValue<string>("CustomerID"); string customerName = reader.GetValue<string>("ContactName"); Console.WriteLine($"Customer '{customerName}' with ID '{customerID}' has VIP membership discount."); } } else { Console.WriteLine($"No VIP members found"); } |
결론
명확하게 NCache 효과적인 데이터 캐싱과 그룹, 태그, 명명된 태그 검색을 위한 다양하고 강력한 기능을 제공하여 캐시된 데이터를 특정 속성에 따라 분류하고 다음을 사용하여 검색합니다. NCache API 또는 SQL과 유사한 쿼리. 이러한 기능은 더 빠른 데이터 액세스, 데이터베이스 로드 감소 및 애플리케이션 성능 향상을 가능하게 하므로 캐싱을 위한 훨씬 더 강력한 옵션이 됩니다. 다음과 같은 강력한 기능을 활용하십시오. NCache 지금 무료 평가판을 시작하세요!