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

명명된 태그로 데이터 추가/업데이트

명명된 태그를 캐시 항목과 연결하려면 명명된 태그 목록을 제공해야 하며, 각각에는 다음과 같은 두 개의 매개변수가 있습니다. 키 태그의 이름인 문자열로, 가치 키에 할당된 값인 기본 유형으로. NCache 그러면 객체를 이러한 명명된 태그와 연결할 수 있습니다. 명명된 태그를 사용하여 캐시에 항목을 추가한 다음, 이전에 추가한 명명된 태그를 사용하여 캐시에서 해당 항목을 검색할 수 있습니다. 특정 명명된 태그가 있는 항목이 이미 캐시에 추가된 경우, NCache 이 기능은 사용자가 캐시에 이미 존재하는 명명된 태그를 업데이트할 수 있는 옵션을 제공합니다. 이를 통해 개발자는 런타임에 캐시 항목에 대한 검색 가능한 인덱스를 생성할 수 있습니다.

사전 조건

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

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

명명된 태그 추가

NCache 맞춤 클래스를 제공하고, CacheItem 캐시에 데이터를 추가하는 데 사용할 수 있습니다. 이 클래스는 데이터를 value 속성으로 캡슐화합니다. CacheItem 또한 개체와 관련된 추가 사양을 property 명명된 태그 클래스의. 다음 예제에서 명명된 태그는 다음과 같이 할당하여 설정됩니다. property of CacheItem.

  • . NET
  • 자바
  • Python
  • Node.js를
  • 레거시 API
try
{
  // Precondition: Cache is already connected

  // In an online-store, VIP members are offered 10% discount
  // A customer with VIP membership has signed in to the website

  string customerKey = "Customer:ALFKI";
  Customer customer = cache.Get<Customer>(customerKey);

  // Get customer from database if not found in cache
  if (customer == null)
  {
      // Get customer from the database
      customer = FetchCustomerFromDB("ALFKI");

      // Create a new CacheItem
      var cacheItem = new CacheItem(customer);

      // 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);
  }
}
catch (OperationFailedException ex)
{
    // NCache specific exception
    if(ex.ErrorCode == NCacheErrorCodes.KEY_ALREADY_EXISTS)
    {
        // An item with the same key already exists
    }
    else
    {
        // Exception can occur due to:
        // Connection Failures 
        // Operation Timeout
        // Operation performed during state transfer
    }
}
catch (Exception ex)
{
    // Any other generic exception like ArgumentNullException or ArgumentException
}   
try
{ 
  // Precondition: Cache is already connected

  // In an online-store, VIP members are offered 10% discount
  // A customer with VIP membership has signed in to the website

  String customerKey = "Customer:ALFKI";
  Customer customer = cache.get(customerKey, Customer.class);

  // Get customer from database if not found in cache
  if (customer == null) {
      // Get customer from the database 
      customer = Customer.fetchCustomerFromDB("ALFKI");
  }
  // Create a new CacheItem
  CacheItem cacheItem = new CacheItem(customer);

  // Creating a Named Tags Dictionary
  NamedTagsDictionary 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.setNamedTags(namedTags);

  cache.add(customerKey, cacheItem);
}
catch (OperationFailedException ex)
{
    if (ex.getErrorCode() == NCacheErrorCodes.KEY_ALREADY_EXISTS)
    {
        // An item with the same key already exists
    }
    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

    # In an online-store, VIP members are offered 10% discount
    # A customer with VIP membership has signed in to the website

    customer_key = "Customer:ALFKI"
    cache_item = cache.get_cacheitem(customer_key)

    # Get customer from cache item if exists
    customer = cache_item.get_value(Customer) if cache_item else None

    # Get customer from database if not found in cache
    if customer is None:
        # Get customer from the database
        customer = Customer.fetch_customer_from_db("ALFKI")

    # Create a new CacheItem
    cache_item = ncache.CacheItem(customer)

    # Creating a Named Tags Dictionary
    customer_named_tag = ncache.NamedTagsDictionary()

    # Adding Named Tags to the Dictionary
    # Where keys are the names of the tags as string type and values are of primitive type
    customer_named_tag.insert("VIP_Membership_Discount", 0.10)

    # Setting the NamedTag property of the cacheItem
    cache_item.set_named_tags(customer_named_tag)

    version = cache.add(customer_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

  // In an online-store, VIP members are offered 10% discount
  // A customer with VIP membership has signed in to the website

  const customerKey = "Customer:ALFKI";
  let customer = cache.get(customerKey);

  // Get customer from database if not found in cache
  if (!customer) 
  {
      // Get customer from the database
      customer = await Customer.fetchCustomerFromDB("ALFKI");
  }

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

  // Creating a Named Tags Dictionary
  var productNamedTag = new ncache.NamedTagsDictionary();

  // Adding Named Tags to the Dictionary where
  // Keys are the names of the tags as string type
  // values are the instances of data, of primitive data types
  productNamedTag.add("VIP_Membership_Discount", 0.10);

  // Setting the Named Tag property of the CacheItem
  cacheItem.setNamedTags(productNamedTag);

  // Add product object to the cache
  var version = await this.cache.add(key, cacheItem);
}
catch (error)
{
    // Handle errors
}  
// Using NCache Enterprise 4.9.1

try
{
  // In an online-store, VIP members are offered 10% discount
  // A customer with VIP membership has signed in to the website

  // Precondition: Cache is already connected

  string customerKey = "Customer:ALFKI";
  Customer customer = (Customer)cache.Get(customerKey);

  // Get customer from database if not found in cache
  if (customer == null)
  {
      // Get customer from the database
      customer = FetchCustomerFromDB("ALFKI");

      // Create a new CacheItem
      CacheItem cacheItem = new CacheItem(customer);

      // 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;

      // Add cacheItem to cache
      cache.Add(customerKey, cacheItem);
  }
}
catch (OperationFailedException ex)
{
    // NCache specific exception
    if(ex.ErrorCode == NCacheErrorCodes.KEY_ALREADY_EXISTS)
    {
        // An item with the same key already exists
    }
    else
    {
        // Exception can occur due to:
        // Connection Failures 
        // Operation Timeout
        // Operation performed during state transfer
    }
}
catch (Exception ex)
{
    // Any other generic exception like ArgumentNullException or ArgumentException
}  
주의 사항

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

CacheItem을 통해 명명된 태그 데이터 업데이트

다음을 통해 명명된 태그 업데이트 CacheItem 항목을 먼저 가져와서 명명된 태그를 수정한 다음 다음을 사용하여 캐시에 다시 삽입해야 합니다. 끼워 넣다 방법.

다음 예제는 먼저 CacheItem, 새로 명명된 태그로 목록을 생성한 다음 CacheItem 수정된 명명된 태그 목록과 함께 캐시에 저장됩니다. 따라서 기존 명명된 태그의 값을 덮어씁니다.

경고

제공 Null 명명된 태그 배열은 ArgumentNullException을 발생시킵니다.

  • . NET
  • 자바
  • Python
  • Node.js를
// Precondition: Cache is already connected

// Store Owner has increased VIP membership discount to 12%

string customerKey = "Customer:ALFKI";
Customer customer = cache.Get<Customer>(customerKey);

// Get the customer from database if not found in the cache
if (customer == null)
{
    customer = FetchCustomerFromDB("ALFKI");
}

// Create a new CacheItem
var cacheItem = new CacheItem(customer);

// Creating a Named Tags Dictionary
var newNamedTags = new NamedTagsDictionary();

// Add Named Tag with the updated discount value to the Dictionary
newNamedTags.Add("VIP_Membership_Discount", 0.12);

// Updates the Named Tags with the new Named Tags
// Overrides the value of the existing Named Tags
cacheItem.NamedTags = newNamedTags;

// Reinserts the updated cacheItem into the cache with the modified Named Tags
cache.Insert(customerKey, cacheItem);
// Precondition: Cache is already connected

// Store Owner has increased VIP membership discount to 12%

String customerKey = "Customer:ALFKI";
Customer customer = cache.get(customerKey, Customer.class);

// Get the customer from database if not found in the cache
if (customer == null) {
    // Fetch customer from database and create a Customer object
    customer = Customer.fetchCustomerFromDB("ALFKI");
}

// Create a new CacheItem
CacheItem cacheItem = new CacheItem(customer);

// Creating a Named Tags Dictionary
NamedTagsDictionary namedTags = new NamedTagsDictionary();

// Add Named Tag with the updated discount value to the Dictionary
namedTags.add("VIP_Membership_Discount", 0.12);

// Updates the Named Tags with the new Named Tags
// Overrides the value of the existing Named Tags
cacheItem.setNamedTags(namedTags);

// Reinserts the updated cacheItem into the cache with the modified Named Tags
cache.insert(customerKey, cacheItem);
# Precondition: Cache is already connected

# Store Owner has increased VIP membership discount to 12%

customer_key = "Customer:ALFKI"
cache_item = cache.get_cacheitem(key)

# Get customer from database if not found in cache
if customer is None:
    # Get customer from the database
    customer = Customer.fetch_customer_from_db("ALFKI")

# Create a Named Tags Dictionary
new_product_named_tag = ncache.NamedTagsDictionary()

# Add Named Tag with the updated discount value to the Dictionary
new_product_named_tag.add("VIP_Membership_Discount", 0.12)

# Updates the Named Tags with the new Named Tags
# Overrides the value of the existing Named Tags
cache_item.set_named_tags(new_product_named_tag)

# Reinsert the updated cacheItem into cache with modified Named Tags
version = cache.insert(key, cache_item)
// Precondition: Cache is already connected
// This is an async method

// Store Owner has increased VIP membership discount to 12%

const customerKey = "Customer:ALFKI";
let customer = cache.get(customerKey);

if (!customer) {
    customer = await fetchCustomerFromDB("ALFKI");
}

// Create a new CacheItem
const cacheItem = new CacheItem(customer);

// Creating a Named Tags Dictionary
var newProductNamedTag = new ncache.NamedTagsDictionary();

// Add Named Tag with the updated discount value to the Dictionary
newProductNamedTag.add("VIP_Membership_Discount", 0.12);

// Updates the Named Tags with the new Named Tags
// Overrides the value of the existing Named Tags
cacheItem.setNamedTags(newProductNamedTag);

// Reinserts the cacheItem into cache with modified Named Tags
var version = await this.cache.insert(key, cacheItem);

추가 자료

NCache 명명된 태그에 대한 샘플 애플리케이션을 제공합니다. GitHub의.

도 참조

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

문의하기

전화

+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.의 등록상표입니다.
맨 위로