NCache 지정된 명명된 태그와 해당 값에 일치하는 캐시 항목을 삭제하는 객체 쿼리를 제공합니다. ExecuteNonQuery API를 사용하면 이러한 태그를 기반으로 효율적인 데이터 삭제를 수행할 수 있습니다. 항목이 명명된 태그와 함께 캐시에 추가되었는지 확인하십시오. 자세한 내용은 다음을 참조하십시오. 명명된 태그가 있는 항목 추가 섹션에서 명명된 태그 생성 및 추가에 대한 자세한 내용을 확인하세요.
사전 조건
사용하기 전에 NCache 클라이언트 측 API를 사용할 때는 다음 필수 조건을 충족해야 합니다.
- .NET 클라이언트 애플리케이션에 다음 NuGet 패키지를 설치하세요.
- 애플리케이션에 다음 네임스페이스를 포함합니다.
- 캐시가 실행 중이어야 합니다.
- 추가되는 데이터가 직렬화 가능.
- 사용자 정의 클래스/검색 가능한 속성 절대로 필요한 것 에 설명된 대로 인덱싱됩니다. 쿼리 인덱스 구성.
- API 세부 정보는 다음을 참조하세요. 아이캐시, ICacheReader, 쿼리 명령, 제거, 비쿼리 실행, 검색 서비스.
- Java 클라이언트 애플리케이션에 대해 다음 Maven 종속성을 추가합니다.
pom.xml 파일 :
<dependency>
<groupId>com.alachisoft.ncache</groupId>
<!--for NCache Enterprise-->
<artifactId>ncache-client</artifactId>
<version>x.x.x</version>
</dependency>
- Node.js 클라이언트 애플리케이션에 다음 모듈을 설치하고 포함시키세요.
- 애플리케이션에 다음 클래스를 포함합니다.
- 캐시가 실행 중이어야 합니다.
- 추가되는 데이터가 직렬화 가능.
- 사용자 정의 클래스/검색 가능한 속성 절대로 필요한 것 에 설명된 대로 인덱싱됩니다. 쿼리 인덱스 구성.
- API 세부 정보는 다음을 참조하세요. 캐시, 제거, 실행하지 않는 쿼리, 쿼리 명령, getSearchService.
통사론
다음 예제에서는 쿼리를 사용하여 명명된 태그와 연관된 항목을 삭제하는 방법을 보여줍니다.
try
{
// Precondition: Cache is already connected
// Items are already present in the cache with Named Tags
// A user wants to end the VIP membership discount offer so this Named Tag needs to be removed from the customer
// All the customers with VIP membership discount Named Tag need to be removed from the cache
// Custom class is query indexed through the NCache Management Center or config.ncconf
// Make sure to use the Fully Qualified Name (FQN)
// Create an SQL Query with the specified criteria
string query = "DELETE FROM FQN.Customer WHERE VIP_Membership_Discount = 0.12 ";
// Use QueryCommand for query execution
var queryCommand = new QueryCommand(query);
// 'rowsAffected' indicates the number of items removed from the cache
int rowsAffected = cache.SearchService.ExecuteNonQuery(queryCommand);
if (rowsAffected==0)
Console.WriteLine($"No VIP members removed");
}
catch (OperationFailedException ex)
{
if (ex.ErrorCode == NCacheErrorCodes.INCORRECT_FORMAT)
{
// Make sure that the query format is correct
}
else
{
// Exception can occur due to:
// Connection Failures
// Operation Timeout
// Operation performed during state transfer
}
}
catch (Exception ex)
{
// Any generic exception like ArgumentException, ArgumentNullException
}
try
{
// Precondition: Cache is already connected
// Items are already present in the cache with Named Tags
// A user wants to end the VIP membership discount offer so this Named Tag needs to be removed from the customer
// All the customers with VIP membership discount Named Tag need to be removed from the cache
// Custom class is query indexed through the NCache Management Center or config.ncconf
// Make sure to use the Fully Qualified Name (FQN)
// Create an SQL Query to remove customers with VIP membership discount
String query = "DELETE FROM FQN.Customer WHERE VIP_Membership_Discount = 0.12 ";
// Use QueryCommand for query execution
QueryCommand queryCommand = new QueryCommand(query);
// 'rowsAffected' indicates the number of items removed from the cache
int rowsAffected = cache.getSearchService().executeNonQuery(queryCommand);
if (rowsAffected > 0)
{
System.out.println(rowsAffected + " VIP members removed from cache.");
}
else
{
System.out.println("No VIP members removed");
}
}
catch (OperationFailedException ex)
{
if (ex.getErrorCode() == NCacheErrorCodes.INCORRECT_FORMAT) {
// Make sure your format is correct
}
else
{
// Exception can occur due to:
// Connection Failures
// Operation Timeout
// Operation performed during state transfer
}
}
catch (Exception ex)
{
// Any generic exception like IllegalArgumentException or NullPointerException
}
try:
# Precondition: Cache is already connected
# Items are already present in the cache with Named Tags
# A user wants to end the VIP membership discount offer so this Named Tag needs to be removed from the customer
# All the customers with VIP membership discount Named Tag need to be removed from the cache
# Custom class is query indexed through the NCache Management Center or config.ncconf
# Delete data from cache with the specified criteria
# Make sure to use the Fully Qualified Name(FQN)
query = "DELETE FROM FQN.Customer WHERE VIP_Membership_Discount = ?"
# Use QueryCommand for query execution
query_command = ncache.QueryCommand(query)
parameter = {"VIP_Membership_Discount": 0.12}
query_command.set_parameters(parameter)
search_service = cache.get_search_service()
# 'rows_affected' number of items removed from cache
rows_affected = search_service.execute_non_query(query_command)
except Exception as error:
# Exception can occur due to:
# Connection Failures
# Operation Timeout
# Operation during state transfer
print("An error occurred:", str(error))
try
{
// Precondition: Cache is already connected
// This is an async method
// Items are already present in the cache with Named Tags
// A user wants to end the VIP membership discount offer so this Named Tag needs to be removed from the customer
// All the customers with VIP membership discount Named Tag need to be removed from the cache
// Custom class is query indexed through the NCache Management Center or config.ncconf
// Make sure to use the Fully Qualified Name (FQN)
// Create an SQL Query with the specified criteria
var query = "DELETE FROM FQN.Customer WHERE VIP_Membership_Discount = ?";
// Use QueryCommand for query execution
var queryCommand = new ncache.QueryCommand(query);
var parameters = new Map();
parameters.set("VIP_Membership_Discount",0.12);
queryCommand.setParameters(parameters);
var searchService = await this.cache.getSearchService();
// 'rowsAffected' number of items removed from cache
var rowsAffected = await searchService.executeNonQuery(queryCommand);
}
catch (error)
{
// Handle errors
}
주의 사항
작업이 안전하도록 하려면 에 설명된 대로 응용 프로그램 내에서 잠재적인 예외를 처리하는 것이 좋습니다. 처리 실패.
객체 쿼리에 대한 자세한 내용을 보려면 다음을 참조하세요. 에 대한 SQL 참조 NCache 안내
명명된 태그를 사용하여 데이터를 제거하는 또 다른 접근 방식은 데이터를 쿼리한 다음 다음을 사용하여 데이터를 가져오는 것입니다. 제거 가져온 데이터에서 선택된 값을 제거하는 메서드입니다. 이 방법을 사용하면 특정 명명된 태그와 연결된 항목이 제거됩니다. 그러나 이 방법은 네트워크 호출 횟수를 증가시켜 사용자에게 효율적이지 않으므로 권장하지 않습니다. 키를 사용하여 캐시 항목을 제거하는 방법에 대한 자세한 내용은 다음을 참조하십시오. 캐시에서 데이터 제거.
추가 자료
NCache 태그에 대한 샘플 애플리케이션을 제공합니다. GitHub의.
도 참조
.그물: Alachisoft.NCache.런타임.캐싱 네임 스페이스.
자바 : com.alachisoft.ncache.런타임.캐싱 네임 스페이스.
파이썬 : ncache.런타임.캐싱 클래스입니다.
Node.js : NamedTags사전 클래스입니다.