CacheItem 클래스

정의

캐시의 각 캐시 엔트리를 나타냅니다.

public ref class CacheItem
public class CacheItem
type CacheItem = class
Public Class CacheItem
상속
CacheItem

예제

다음 예제에서는 사용 하는 방법의 CacheItem 캐시 항목으로 파일의 내용을 저장 하는 클래스입니다.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.Caching;
using System.IO;

public partial class _Default : System.Web.UI.Page
{

    protected void Button1_Click(object sender, EventArgs e)
    {
        ObjectCache cache = MemoryCache.Default;

        CacheItem fileContents = cache.GetCacheItem("filecontents");

        if (fileContents == null)
        {
            CacheItemPolicy policy = new CacheItemPolicy();

            List<string> filePaths = new List<string>();
            string cachedFilePath = Server.MapPath("~") +
                "\\cacheText.txt";

            filePaths.Add(cachedFilePath);

            policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths));

            // Fetch the file contents
            string fileData = File.ReadAllText(cachedFilePath);

            fileContents = new CacheItem("filecontents", fileData);

            cache.Set(fileContents, policy);
        }
        Label1.Text = (fileContents.Value as string);
    }
}
Imports System.Runtime.Caching
Imports System.IO

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim cache As ObjectCache = MemoryCache.Default

        Dim fileContents As CacheItem = cache.GetCacheItem("filecontents")

        If fileContents Is Nothing Then
            Dim policy As New CacheItemPolicy()

            Dim filePaths As New List(Of String)()

            Dim CachedFilePaths As String = Server.MapPath("~") & "\cacheText.txt"

                filePaths.Add(CachedFilePaths)

            policy.ChangeMonitors.Add(New HostFileChangeMonitor(filePaths))

            ' Fetch the file contents 
            Dim fileData As String = File.ReadAllText(CachedFilePaths)

            fileContents = New CacheItem("filecontents", fileData)

            cache.Set(fileContents, policy)
        End If
        Label1.Text = TryCast(fileContents.Value, String)
    End Sub
End Class

설명

합니다 CacheItem 클래스를 사용 하 여 영역을 포함할 수 있는 캐시 항목의 논리적 표현을 제공 합니다 RegionName 속성입니다. 기본 ASP.NET 캐시 구현이 캐시 엔트리 키/값 쌍을 경우

캐시의 항목에는 없는 CacheItem 인스턴스. 대신, 캐시 공급자는 모든 내부 형식으로 캐시 항목을 저장할 수 있습니다. 그러나 캐시 API를 사용 하려면 캐시 공급자에 캐시 엔트리를 변환할 수 있게 되기를 CacheItem 인스턴스 (또는 그 반대로).

사용자 지정 캐시 구현을 상속할 수는 CacheItem 클래스는 캐시 항목에 대 한 추가 정보를 제공 합니다.

상속자 참고

클래스에는 ObjectCache 캐시 데이터 추가, 가져오기 및 업데이트를 지원하는 메서드가 있으며 이러한 모든 메서드에는 클래스를 지원하는 CacheItem 오버로드가 있습니다. 따라서 사용자 지정 캐시 구현은 확장 클래스를 만들고 해당 확장 CacheItem 클래스를 캐시 항목에 대한 기존 ObjectCache API와 함께 사용할 수 있습니다.

생성자

CacheItem(String)

캐시 엔트리의 지정된 키를 사용하여 새 CacheItem 인스턴스를 초기화합니다.

CacheItem(String, Object)

캐시 엔트리의 지정된 키 및 값을 사용하여 새 CacheItem 인스턴스를 초기화합니다.

CacheItem(String, Object, String)

캐시 엔트리의 지정된 키, 값 및 영역을 사용하여 새 CacheItem 인스턴스를 초기화합니다.

속성

Key

CacheItem 인스턴스의 고유 식별자를 가져오거나 설정합니다.

RegionName

캐시에서 CacheItem 엔트리를 포함하는 캐시에 있는 영역의 이름을 가져오거나 설정합니다.

Value

CacheItem 인스턴스의 데이터를 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보