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

캐시의 슬라이딩 만료

슬라이딩 만료 NCache 캐시는 자주 접근하는 데이터를 유지하고 특정 기간 동안 사용되지 않은 데이터를 자동으로 제거하는 동적 메모리 관리 전략입니다. 접근할 때마다 TTL(Time-to-Live) 값을 재설정함으로써, 자주 접근하는 항목을 캐시에 유지하면서 비활성 데이터를 제거하는 데 도움이 됩니다.

슬라이딩 만료(Sliding Expiration)는 지정된 시간 간격 내에 데이터에 접근하면 해당 캐시 항목의 TTL(Time-to-Live) 값을 재설정합니다. 이를 통해 특정 캐시 항목이 만료되는 것을 방지하고 애플리케이션 활동이 많을 때에도 데이터를 최신 상태로 유지할 수 있습니다. 예를 들어, 세션 만료 시간이 10분으로 설정된 경우, 6분째에 해당 세션에 접근하면 캐시에 저장된 세션의 수명이 10분 더 연장됩니다.

사전 조건

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

  • . NET
  • 자바
  • Python
  • Node.js를
  • 레거시 API
  • .NET 클라이언트 애플리케이션에 다음 NuGet 패키지를 설치하세요.
    • 기업 : Alachisoft.NCache.SDK
    • 오픈 소스 : Alachisoft.NCache오픈소스 SDK
  • 애플리케이션에 다음 네임스페이스를 포함합니다.
    • Alachisoft.NCache.고객
    • Alachisoft.NCache.런타임.예외
    • Alachisoft.NCache.런타임.캐싱
  • 캐시가 실행 중이어야 합니다.
  • 추가되는 데이터가 직렬화 가능.
  • API 세부 정보는 다음을 참조하세요. 아이캐시, 캐시 아이템, 포함, 카운트, 만료, 끼워 넣다.
  • 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 세부 정보는 다음을 참조하세요. 캐시, 캐시 아이템, 이 포함되어 있습니다, getCount, 만료, 삽입하다.
  • Python 클라이언트 애플리케이션에 다음 패키지를 설치하세요.
    • 기업 : ncache-클라이언트
  • 애플리케이션에서 다음 패키지를 가져옵니다.
    • 에 ncache.client 가져오기*
    • 에 ncache.runtime.caching 가져오기 *
  • 캐시가 실행 중이어야 합니다.
  • 추가되는 데이터가 직렬화 가능.
  • API 세부 정보는 다음을 참조하세요. 캐시, 캐시 아이템, 이 포함되어 있습니다, get_count, 삽입하다, 만료.
  • Node.js 클라이언트 애플리케이션에 다음 모듈을 설치하고 포함시키세요.
    • 기업 : ncache-클라이언트
  • 애플리케이션에 다음 클래스를 포함합니다.
    • 캐시
    • 만료
  • 캐시가 실행 중이어야 합니다.
  • 추가되는 데이터가 직렬화 가능.
  • API 세부 정보는 다음을 참조하세요. 캐시, 캐시 아이템, 이 포함되어 있습니다, 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 웹 사이트.

API를 통해 슬라이딩 만료를 설정하는 방법

캐시 항목을 추가하거나 업데이트하여 만료일을 설정할 수 있습니다. 끼워 넣다 방법. 그만큼 CacheItem 에서 제공하는 사용자 정의 클래스입니다. NCache 캐시에 데이터를 추가하는 데 사용할 수 있으며 이 클래스의 개체와 관련된 추가 메타데이터를 설정할 수도 있습니다. 이 메타데이터는 만료, 종속성 등과 같은 항목의 속성을 정의합니다.

다음 예는 다음 값을 설정합니다. Expiration 속성을 5분 동안 슬라이딩 만료로 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);

  // Resetting TTL to optimize memory
  var expiration = new Expiration(ExpirationType.Sliding, 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.Sliding, 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
    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.SLIDING, 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.Sliding, 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
  Product product = FetchProductFromDB("1001");

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

  // Adding sliding expiration of 5 min through Add API
  cache.Add(key, product, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 5, 0), 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
}
주의 사항

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

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

다음을 사용하여 API에서 슬라이딩 만료를 지정할 수 있습니다. DefaultSliding DefaultSlidingLonger 에 구성된 값 NCache 관리센터 또는 config.ncconf. 이는 필요한 경우 코드를 변경하지 않고도 외부에서 값을 변경할 수 있는 유연성을 제공합니다.

다음 코드는 구성된 기본 만료(DefaultSliding 이 경우, 항목을 요청하면 키가 존재하지 않으면 캐시에 추가하고, 존재하지 않으면 기존 항목의 만료 시간을 새 값으로 업데이트합니다. 설정된 시간 간격 내에 항목에 접근하지 않으면 항목이 만료됩니다. 그렇지 않으면 항목의 수명은 설정된 시간 간격만큼 연장됩니다.

중대한

기본 만료를 활성화하려면 다음을 통해 활성화해야 합니다. NCache 관리 센터 또는 config.ncconf. 기본 만료를 위해 API를 전달했지만 이를 통해 구성되지 않은 경우 NCache 관리센터 또는 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 product
var cacheItem = new CacheItem(product);

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

cacheItem.Expiration = expiration;

// Resetting TTL to optimize memory
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 product
CacheItem cacheItem = new CacheItem(product);

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

cacheItem.setExpiration(expiration);

// Add/Update item into the cache with expiration
CacheItemVersion version = cache.insert(key, cacheItem);
# 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.DEFAULT_SLIDING)

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 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
var expiration = new ncache.Expiration(ncache.ExpirationType.DefaultSliding);

cacheItem.setExpiration(expiration);

// Add/Update item into the cache with 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);

// Adding Default Sliding expiration with configured value
cache.Add(key, product, null, Cache.NoAbsoluteExpiration, Cache.DefaultSliding, CacheItemPriority.Default);

추가 자료

NCache 슬라이딩 만료에 대한 샘플 애플리케이션을 제공합니다. 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.의 등록상표입니다.
맨 위로