캐시의 데이터 구조에 대한 무효화 속성 구성
NCache 분산 데이터 구조에 대한 무효화 메커니즘을 제공하여 캐시에서의 수명 및 제거 동작을 제어합니다. 이러한 메커니즘은 다음을 통해 구성됩니다. DataTypeAttributes 데이터 구조 생성 시 지정되는 클래스이며, 지원되는 모든 분산 데이터 구조에 적용됩니다. 이러한 설정은 데이터 구조의 핵심 동작을 정의하므로 초기화 시에 지정해야 하며, 이후에는 변경할 수 없습니다.
데이터 구조는 다음을 사용하여 캐시에서 무효화할 수 있습니다.
이러한 속성은 다음을 사용하여 데이터 구조를 생성하는 동안 지정됩니다. DataTypeAttributes 클래스로 지정되며, 데이터 구조가 캐시에 생성된 후에는 수정할 수 없습니다. 또한 이러한 무효화 속성은 모든 데이터 구조에 대해 지정할 수 있습니다.
주의 사항
주요 종속성도 구성할 수 있습니다. CacheItem 그리고 데이터 구조.
사전 조건
사용하기 전에 NCache 클라이언트 측 API를 사용할 때 다음 전제 조건을 충족하는지 확인하십시오.
- .NET 클라이언트 애플리케이션에 다음 NuGet 패키지를 설치하세요.
- 기업: Alachisoft.NCache.SDK
- 오픈 소스: Alachisoft.NCache오픈소스 SDK
- 애플리케이션에 다음 네임스페이스를 포함합니다.
- 캐시가 실행 중이어야 합니다.
- 추가되는 데이터가 직렬화 가능.
- API 세부 정보는 다음을 참조하세요. 아이캐시, 데이터 유형 속성, 캐시항목우선순위, 만료, 만료 유형, 키 종속성, IDistributedHashSet, IDataTypeManager, CreateHashSet, 데이터 유형 관리자.
데이터 구조에 무효화 속성 사용
다음 예제는 분산 데이터 구조에 대한 무효화 속성을 보여줍니다. 주문 ID 집합.NET 및 Java 예제는 HashSet을 사용하는 반면 Node.js 예제는 List를 사용합니다.
try
{
// Precondition: Cache is already connected
// Product exists in cache with key "Product:1001"
string productKey = "Product:1001";
// Specify attributes for HashSet
var attributes = new DataTypeAttributes();
// Specify priority for eviction
attributes.Priority = CacheItemPriority.High;
// Specify Absolute expiration of 15 minutes
var expiration = new Expiration(ExpirationType.Absolute, TimeSpan.FromMinutes(15));
attributes.Expiration = expiration;
// Specify key dependency on productKey
var keyDependency = new KeyDependency(productKey);
attributes.Dependency = keyDependency;
// Create HashSet which is dependent on product:1001
// Specify unique cache key for set
string orderKey = "OrderIDSet";
IDistributedHashSet<int> orderIDSet = cache.DataTypeManager.CreateHashSet<int>(orderKey, attributes);
// Check if the orderIDSet exists in cache:
// After 15 minutes or
// If product is modified in cache
}
catch (OperationFailedException ex)
{
// NCache specific exception
if(ex.ErrorCode == NCacheErrorCodes.KEY_ALREADY_EXISTS)
{
// An item with the same key already exists
}
else if (ex.ErrorCode == NCacheErrorCodes.CACHEITEM_IN_DATA_STRUCTURES)
{
// Data structures cannot be of CacheItem type
// CacheItems cannot be added in data structures
}
else
{
// NCache specific exception
// Exception can occur due to:
// Connection Failures
// Operation Timeout
// Operation performed during state transfer
}
}
catch (Exception ex)
{
// Any generic exception like ArgumentNullException or ArgumentException
}
주의 사항
작업이 안전하도록 하려면 에 설명된 대로 응용 프로그램 내에서 잠재적인 예외를 처리하는 것이 좋습니다. 처리 실패.
추가 자료
NCache 데이터 구조로 무효화 속성을 구성하기 위한 샘플 애플리케이션 제공 GitHub의.
도 참조
.그물: Alachisoft.NCache.클라이언트.데이터 유형 네임 스페이스.
자바 : com.alachisoft.ncache.client.데이터 구조 네임 스페이스.
Node.js : 데이터 구조 관리자 클래스입니다.