• Facebook
  • 트위터
  • 유튜브
  • 라인드인
  • RSS
  • 기술 문서
  • 비교
  • 블로그
  • 다운로드
  • 문의하기
다운로드
목차 표시/숨기기

캐시의 절대 데이터 만료

절대 만료일 NCache 정확한 클라이언트 지정 날짜 및 시간에 캐시 항목을 무효화하여 데이터 일관성을 보장합니다. 캐시에 일정 시간 동안만 필요한 항목에는 절대 만료 시간을 지정할 수 있습니다. 예를 들어, 특정 제품에 대해 24시간 동안 깜짝 할인 행사를 진행하는 경우, 해당 제품은 24시간의 절대 만료 시간으로 캐시에 저장되어 할인 행사가 종료되는 즉시 캐시에서 삭제됩니다.

또한,이 DateTime 값은 다음으로 변환됩니다. UTC 시간 캐시 서버와 클라이언트가 서로 다른 시간대에 있는 상황을 처리하기 위한 것입니다. 따라서 항목은 사용자가 지정한 정확한 시간에 만료됩니다.

사전 조건

사용하기 전에 NCache 클라이언트 측 API를 사용할 때는 다음 필수 조건을 충족해야 합니다.

  • . NET
  • 자바
  • Python
  • Node.js를
  • 레거시 API
  • .NET 클라이언트 애플리케이션에 다음 NuGet 패키지를 설치하세요.
    • 기업 : Alachisoft.NCache.SDK
    • 오픈 소스 : Alachisoft.NCache오픈소스 SDK
  • 애플리케이션에 다음 네임스페이스를 포함합니다.
    • Alachisoft.NCache.고객
    • Alachisoft.NCache.런타임.예외
    • Alachisoft.NCache.런타임.캐싱
  • 캐시가 실행 중이어야 합니다.
  • 추가되는 데이터가 직렬화 가능.
  • API 세부 정보는 다음을 참조하세요. 아이캐시, 캐시 아이템, CacheItem속성, 포함, 카운트, 만료, 끼워 넣다, 업데이트 속성.
  • Java 클라이언트 애플리케이션에 대해 다음 Maven 종속성을 추가합니다. pom.xml 파일 :
<dependency>
    <groupId>com.alachisoft.ncache</groupId>
    <!--for NCache Enterprise-->
    <artifactId>ncache-client</artifactId>
    <version>x.x.x</version>
</dependency>
  • Java 클라이언트 애플리케이션에서 다음 패키지를 가져옵니다.
    • import **클라이언트 이름**
    • import com.alachisoft.ncache.런타임.예외.*;
    • import 영어: com.alachisoft.ncache.runtime.caching.*;
  • 캐시가 실행 중이어야 합니다.
  • 추가되는 데이터가 직렬화 가능.
  • API 세부 정보는 다음을 참조하세요. 캐시, 캐시 아이템, CacheItem속성, 이 포함되어 있습니다, getCount, 만료, 삽입하다, 업데이트 속성.
  • Python 클라이언트 애플리케이션에 다음 패키지를 설치하세요.
    • 기업 : ncache-클라이언트
  • 애플리케이션에서 다음 패키지를 가져옵니다.
    • 에 ncache.client 가져오기*
    • 에 ncache.runtime.caching 가져오기 *
  • 캐시가 실행 중이어야 합니다.
  • 추가되는 데이터가 직렬화 가능.
  • API 세부 정보는 다음을 참조하세요. 캐시, 캐시 아이템, CacheItem속성, 이 포함되어 있습니다, 만료.
  • Node.js 클라이언트 애플리케이션에 다음 모듈을 설치하고 포함시키세요.
    • 기업 : ncache-클라이언트
  • 애플리케이션에 다음 클래스를 포함합니다.
    • 캐시
    • 만료
  • 캐시가 실행 중이어야 합니다.
  • 추가되는 데이터가 직렬화 가능.
  • API 세부 정보는 다음을 참조하세요. 캐시, 캐시 아이템, CacheItem속성, 이 포함되어 있습니다, getCount, 만료, 삽입하다, 업데이트 속성.
  • .NET 클라이언트 애플리케이션에 다음 NuGet 패키지 중 하나를 설치하세요.
    • 기업 : Install-Package Alachisoft.NCache.SDK -Version 4.9.1.0
  • 새로운 콘솔 애플리케이션을 만듭니다.
  • 추가되는 데이터가 직렬화 가능.
  • 추가 NCache 참고자료 위치를 찾아서 %NCHOME%\NCache\bin\assembly\4.0 추가 Alachisoft.NCache.Web Alachisoft.NCache.Runtime 적절한.
  • 포함시키다 Alachisoft.NCache.Web.Caching 애플리케이션의 네임스페이스.
  • 에 대한 자세한 내용을 보려면 NCache 레거시 API를 다운로드하세요 NCache 4.9 문서는 다음과 같이 사용 가능합니다. .지퍼 에 파일 Alachisoft 웹 사이트.

절대 만료 기간이 있는 항목을 추가 또는 업데이트하는 방법

Insert 표준입니다 NCache 애플리케이션 상태를 캐시와 동기화하는 API입니다. 이 API를 사용하면 캐시 항목을 쉽게 추가하거나 업데이트하고 만료 시간을 설정할 수 있습니다. 끼워 넣다 방법. 그만큼 CacheItem 에서 제공하는 사용자 정의 클래스입니다. NCache 이 기능을 사용하면 캐시에 데이터를 추가할 수 있을 뿐 아니라 객체와 관련된 추가 메타데이터를 설정할 수도 있습니다. 이 메타데이터는 만료, 종속성 등과 같은 항목의 속성을 정의합니다.

다음 예는 다음 값을 설정합니다. Expiration 해당 속성은 5분 동안 절대 만료됩니다. CacheItem. 그것은 추가합니다 CacheItem키가 캐시에 존재하지 않으면 캐시에 저장하고, 존재하면 캐시를 업데이트합니다. CacheItem 그런 다음 5분 후에 캐시에서 제거됩니다.

팁

다음을 통해 만료를 모니터링/확인할 수 있습니다.

  • "캐시 개수" 카운터 NCache 모니터 or PerfMon 카운터.
  • 사용 cache.Contains 만료 간격이 경과한 후.
  • 사용 cache.Count 만료를 지정하기 전과 후에.
  • . NET
  • 자바
  • Python
  • Node.js를
  • 레거시 API
try
{
  // Precondition: Cache is already connected
  // Get product from database against given product ID
  Product product = FetchProductFromDB(1001);

  // Generate a unique cache key for this product
  string key = $"Product:{product.ProductID}";

  // Create a new CacheItem for this product
  var cacheItem = new CacheItem(product);

  // Set Expiration TimeSpan
  var expiration = new Expiration(ExpirationType.Absolute, TimeSpan.FromMinutes(5));

  cacheItem.Expiration = expiration;

  // Add/Update item with expiration
  cache.Insert(key, cacheItem);
}
catch (OperationFailedException ex)
{
    // Exception can occur due to:
    // Connection Failures 
    // Operation Timeout
    // Operation performed during state transfer
}
catch (Exception ex)
{
    // Any generic exception like ArgumentNullException or ArgumentException
}
try
{
  // Precondition: Cache is already connected
  // Get product from database against given product ID
  Product product = fetchProductFromDB(1001);

  // Generate a unique cache key for this product
  String key = "Product:" + product.getProductID();

  // Create a new CacheItem for this product
  CacheItem cacheItem = new CacheItem(product);

  // Set Expiration type and TimeSpan
  Expiration expiration = new Expiration(ExpirationType.Absolute, TimeSpan.FromMinutes(5));

  cacheItem.setExpiration(expiration);

  // Add/Update item in cache with expiration
  cache.insert(key, cacheItem);
}
catch (OperationFailedException ex)
{
    // 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
    # Get product from database against given product ID
    product = fetch_product_from_db()

    # Generate a unique cache key for this product
    key = "Product:" + product.get_product_id()

    # Create a new CacheItem for this product
    cache_item = ncache.CacheItem(product)

    # Set Expiration type and TimeSpan
    expiration = ncache.Expiration(ncache.ExpirationType.ABSOLUTE, ncache.TimeSpan.from_minutes(5))

    cache_item.set_expiration(expiration)

    # Add/Update item in cache with expiration
    cache.insert(key, cache_item)

except Exception as error:
    # Exception can occur due to:
    # Connection Failures
    # Operation Timeout
    # Operation during state transfer
    print("An error occurred:", str(error))
try
{
  // This is an async method
  // Precondition: Cache is already connected
  // Get product from database against given product ID
  var product = this.fetchProductFromDB(1001);

  // Generate a unique cache key for this product
  var key = "Product:" + product.getProductID();

  // Create a new CacheItem for this product
  // You also need to specify the FQN (Fully Qualified Name) of the class
  var cacheItem = new ncache.CacheItem(product,"FQN.Product");

  // Set Expiration type and TimeSpan
  var expiration = new ncache.Expiration(ncache.ExpirationType.Absolute, ncache.TimeSpan.FromMinutes(5));

  cacheItem.setExpiration(expiration);

  // Add/Update item in cache with expiration
  await this.cache.insert(key, cacheItem);
}
catch (error)
{
    // Handle errors
}
// Using NCache Enterprise 4.9.1

try
{
  // Precondition: Cache is already connected
  // Get product from database against given product ID
  Product product = FetchProductFromDB(1001);

  // Generate a unique cache key for this product
  string key = $"Product:{product.ProductID}";
  CacheItem cacheItem = new CacheItem(product);

  // Updating absolute expiration of 5 min through Add API.
  cache.Insert(key, product, null, System.DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Default);
}
catch (OperationFailedException ex)
{
    // Exception can occur due to:
    // Connection Failures 
    // Operation Timeout
    // Operation performed during state transfer
}
catch (Exception ex)
{
    // Any generic exception like ArgumentNullException or ArgumentException
}
주의 사항

작업이 안전하도록 하려면 에 설명된 대로 응용 프로그램 내에서 잠재적인 예외를 처리하는 것이 좋습니다. 처리 실패.

기본 만료 시간이 설정된 항목을 추가 또는 업데이트하는 방법

사용 DefaultAbsolute 설정된 값을 통해 데이터를 관리할 수 있습니다. NCache 관리센터 또는 config.ncconf 애플리케이션 코드 재배포 없이도 가능합니다. API를 사용하여 절대 만료 시간을 지정할 수 있습니다. DefaultAbsolute DefaultAbsoluteLonger. 이는 필요한 경우 코드를 변경하지 않고도 외부에서 값을 변경할 수 있는 유연성을 제공합니다.

다음 코드는 구성된 기본 만료(DefaultAbsolute 이 경우, 항목을 입력받아 키가 존재하지 않으면 캐시에 추가하고, 키가 존재하면 만료 시간을 설정하여 항목을 업데이트합니다. 설정된 시간이 경과하면 항목이 만료됩니다.

중대한

기본 만료 기능을 활성화하려면 다음을 통해 활성화해야 합니다. NCache 관리 센터 or config.ncconf.

  • . NET
  • 자바
  • Python
  • Node.js를
  • 레거시 API
// Precondition: Cache is already connected
// Get product from database against given product ID
Product product = FetchProductFromDB(1001);

// Generate a unique cache key for this product
string key = $"Product:{product.ProductID}";

// Create a CacheItem instance for the product
var cacheItem = new CacheItem(product);

// Set Expiration type
var expiration = new Expiration(ExpirationType.DefaultAbsolute);

cacheItem.Expiration = expiration;

// Add/Update the item in the cache with default expiration
CacheItemVersion version = cache.Insert(key, cacheItem);
// Precondition: Cache is already connected
// Get product from database against given product ID
Product product = fetchProductFromDB(1001);

// Generate a unique cache key for this product
String key = "Product:" + product.getProductID();

// Create a CacheItem instance for the product
CacheItem cacheItem = new CacheItem(product);

// Set Expiration type
Expiration expiration = new Expiration(ExpirationType.DefaultAbsolute);

cacheItem.setExpiration(expiration);

// Add/Update the item in the cache with default expiration
CacheItemVersion version = cache.insert(key, cacheItem);
# Precondition: Cache is already connected
# Get product from database
product = fetch_product_from_db()

# Generate a unique cache key for this product
key = "Product:" + product.get_product_id()

# Create a new CacheItem for this product
cache_item = ncache.CacheItem(product)

# Set Expiration type and TimeSpan
expiration = ncache.Expiration(ncache.ExpirationType.DEFAULT_ABSOLUTE)

cache_item.set_expiration(expiration)

# Add/Update item in cache with expiration
version = cache.insert(key, cache_item)
// Precondition: Cache is already connected
// This is an async method
// Get product from database against given product ID
var product = this.fetchProductFromDB(1001);

// Generate a unique cache key for this product
var key = "Product:" + product.getProductID();

// Create a CacheItem instance for the product
// You also need to specify the FQN(Fully Qualified Name) of the class
var cacheItem = new ncache.CacheItem(product,"FQN.Product");

// Set Expiration TimeSpan
var expiration = new ncache.Expiration(ncache.ExpirationType.DefaultAbsolute);

cacheItem.setExpiration(expiration);

var version = await this.cache.insert(key, cacheItem);
// Using NCache Enterprise 4.9.1
// Precondition: Cache is already connected

// Get product from database against given product ID
Product product = FetchProductFromDB("1001");

// Generate a unique cache key for this product
string key = $"Product:{product.ProductID}";
CacheItem cacheItem = new CacheItem(product);

// Updating absolute expiration of 5 min through Add API.
cache.Insert(key, product, null, Cache.DefaultAbsolute, Cache.NoSlidingExpiration, CacheItemPriority.Default);

기존 캐시 항목에 대한 절대 만료 설정 방법

NCache 또한 기존 캐시 항목을 캐시에 다시 삽입하지 않고도 절대 만료 시간을 설정할 수 있는 유연성을 제공합니다. 이는 다음을 통해 수행됩니다. CacheItemAttributes 클래스는 AbsoluteExpiration 캐시 항목에 설정할 속성입니다. 이 속성은 캐시에서 항목이 무효화될 정확한 날짜와 시간을 설정합니다. 그런 다음 이 속성은 항목의 기존 키에 적용됩니다. UpdateAttributes 의 방법 ICache.

다음 예시는 만료 시간이 설정되지 않은 캐시 내 기존 항목에 대해 절대 만료 시간을 설정하는 방법을 보여줍니다. 이렇게 하면 항목을 캐시에 다시 추가하거나 삽입할 필요가 없습니다.

  • . NET
  • 자바
  • Python
  • Node.js를
  • 레거시 API
// Precondition: Cache is already connected
// Precondition: Item already exists in cache
string key = "Product:1001";

// Create a CacheItemAttribute for absolute expiration and set its value to 5 seconds
var attr = new CacheItemAttributes();
attr.AbsoluteExpiration = DateTime.Now.AddSeconds(5);

// Set Absolute Expiration of 5 seconds against existing key
cache.UpdateAttributes(key, attr);
// Precondition: Cache is already connected
// Precondition: Item already exists in cache
String key = "Product:1001";

// Create a CacheItemAttribute for absolute expiration and set its value to 5 seconds
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 5);

CacheItemAttributes attr = new CacheItemAttributes();

attr.setAbsoluteExpiration(calendar.getTime());

// Set Absolute Expiration of 5 seconds against existing key
cache.updateAttributes(key, attr);
# Precondition: Cache is already connected
# Precondition: Item already exists in cache
key = "Product:1001"

# Create a CacheItemAttribute for absolute expiration and set its value to 5 seconds
time = datetime.now() + timedelta(seconds=5)
attr = ncache.CacheItemAttributes()

attr.set_absolute_expiration(time)

# Set Absolute Expiration of 5 seconds against existing key
cache.update_attributes(key, attr)
// This is an async method
// Precondition: Cache is already connected
// Precondition: Item already exists in cache
var key = "Product:1001";

// Create a CacheItemAttribute for absolute expiration and set its value to 5 seconds
var time = new Date().getSeconds()+5;
var attr = new ncache.CacheItemAttributes();

attr.setAbsoluteExpiration(time);

// Set Absolute Expiration of 5 seconds against existing key
await this.cache.updateAttributes(key, attr);
// Using NCache Enterprise 4.9.1
// Precondition: Cache is already connected
// Precondition: Item already exists in cache
string key = "1001";

// Get product from database against given product ID
Product product = FetchProductFromDB(key);

//updating AbsoluteLonger expiration with configured value
cache.Insert(key, product, null, Cache.DefaultAbsoluteLonger, Cache.NoSlidingExpiration, CacheItemPriority.Default);

추가 자료

NCache 에서 Absolute Expiration에 대한 샘플 애플리케이션을 제공합니다. GitHub의.

도 참조

.그물: Alachisoft.NCache.런타임.캐싱 네임 스페이스.
자바 : com.alachisoft.ncache.런타임.캐싱 네임 스페이스.
파이썬 : ncache.런타임.캐싱 클래스입니다.
Node.js : 만료 클래스입니다.

문의하기

전화

+1 214-619-2601   (미국)

+44 20 7993 8327   (UK)

 
이메일

sales@alachisoft.com

support@alachisoft.com

NCache
  • 판 비교
  • NCache 아키텍처
  • 벤치 마크
다운로드
가격
놀이터를 사용해보십시오

배포
  • 클라우드(SaaS 및 소프트웨어)
  • 온 프레미스
  • Kubernetes
  • 도커
기술 사용 사례
  • ASP.NET 세션
  • ASP.NET 코어 세션
  • 게시/구독 메시징
  • 실시간 ASP.NET SignalR
  • 사물의 인터넷 IOT ()
  • NoSQL 데이터베이스
  • 스트림 처리
  • 마이크로 서비스
리소스
  • 잡지 기사
  • 제XNUMX자 기사
  • 기사
  • 비디오
  • 백서
  • 쇼
  • 회담
  • 블로그
  • 기술 문서
고객 사례 연구
  • 환자 후기
  • 고객
고객 지원
  • 데모 예약
  • 포럼(Google 그룹스)
  • Tips
회사
  • Leadership
  • 파트너
  • ​뉴스
  • 이벤트
  • 채용 정보
문의하기

  • 영어중국어 (간체)프랑스어독일 사람이탈리아 사람일본제한국어포르투갈어스페인어

  • 문의하기
  •  
  • 사이트 맵
  •  
  • 이용 약관
  •  
  • 개인정보 처리방침
© 저작권 Alachisoft 2002 - . 판권 소유. NCache 는 Diyatech Corp.의 등록상표입니다.
맨 위로