Cache.Insert メソッド
定義
オーバーロード
Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority, CacheItemRemovedCallback) |
依存関係ポリシー、有効期限ポリシー、優先順位ポリシー、および挿入された項目が |
Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemUpdateCallback) |
依存関係、有効期限ポリシー、およびキャッシュから項目が削除される前のアプリケーションへの通知に使用できるデリゲートを指定して、Cache オブジェクトにオブジェクトを挿入します。Inserts an object into the Cache object together with dependencies, expiration policies, and a delegate that you can use to notify the application before the item is removed from the cache. |
Insert(String, Object, CacheDependency) |
ファイル依存関係またはキー依存関係を持つオブジェクトを Cache に挿入します。Inserts an object into the Cache that has file or key dependencies. |
Insert(String, Object) |
項目の位置を参照するキャッシュ キーを指定し、CacheItemPriority 列挙体が提供する既定値を使用して、Cache オブジェクトに項目を挿入します。Inserts an item into the Cache object with a cache key to reference its location, using default values provided by the CacheItemPriority enumeration. |
Insert(String, Object, CacheDependency, DateTime, TimeSpan) |
依存関係ポリシーと有効期限ポリシーを指定して、Cache にオブジェクトを挿入します。Inserts an object into the Cache with dependencies and expiration policies. |
Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority, CacheItemRemovedCallback)
依存関係ポリシー、有効期限ポリシー、優先順位ポリシー、および挿入された項目が Cache
から削除されたことをアプリケーションに通知するために使用できるデリゲートを指定して、Cache オブジェクトにオブジェクトを挿入します。Inserts an object into the Cache object with dependencies, expiration and priority policies, and a delegate you can use to notify your application when the inserted item is removed from the Cache
.
public:
void Insert(System::String ^ key, System::Object ^ value, System::Web::Caching::CacheDependency ^ dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, System::Web::Caching::CacheItemPriority priority, System::Web::Caching::CacheItemRemovedCallback ^ onRemoveCallback);
public void Insert (string key, object value, System.Web.Caching.CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, System.Web.Caching.CacheItemPriority priority, System.Web.Caching.CacheItemRemovedCallback onRemoveCallback);
member this.Insert : string * obj * System.Web.Caching.CacheDependency * DateTime * TimeSpan * System.Web.Caching.CacheItemPriority * System.Web.Caching.CacheItemRemovedCallback -> unit
Public Sub Insert (key As String, value As Object, dependencies As CacheDependency, absoluteExpiration As DateTime, slidingExpiration As TimeSpan, priority As CacheItemPriority, onRemoveCallback As CacheItemRemovedCallback)
パラメーター
- key
- String
オブジェクトの参照に使用されるキャッシュ キー。The cache key used to reference the object.
- value
- Object
キャッシュに挿入するオブジェクト。The object to be inserted in the cache.
- dependencies
- CacheDependency
項目のファイル依存関係またはキャッシュ キー依存関係。The file or cache key dependencies for the item. 依存関係が変化すると、オブジェクトは無効になり、キャッシュから削除されます。When any dependency changes, the object becomes invalid and is removed from the cache. 依存関係がない場合は、このパラメーターには null
が格納されます。If there are no dependencies, this parameter contains null
.
- absoluteExpiration
- DateTime
挿入されたオブジェクトが期限切れとなり、キャッシュから削除される時刻。The time at which the inserted object expires and is removed from the cache. 標準時間から夏時間への変更など、ローカル時間に関する問題を回避するには、このパラメーター値には Now ではなく UtcNow を使用してください。To avoid possible issues with local time such as changes from standard time to daylight saving time, use UtcNow rather than Now for this parameter value. 絶対有効期限を使用している場合は、slidingExpiration
パラメーターは NoSlidingExpiration にする必要があります。If you are using absolute expiration, the slidingExpiration
parameter must be NoSlidingExpiration.
- slidingExpiration
- TimeSpan
挿入されたオブジェクトが最後にアクセスされてからそのオブジェクトが期限切れになるまでの間隔。The interval between the time the inserted object was last accessed and the time at which that object expires. この値が 20 分に相当する場合、オブジェクトは、最後のアクセスから 20 分経過すると有効期限が切れ、キャッシュから削除されます。If this value is the equivalent of 20 minutes, the object will expire and be removed from the cache 20 minutes after it was last accessed. スライド式有効期限を使用している場合は、absoluteExpiration
パラメーターは NoAbsoluteExpiration にする必要があります。If you are using sliding expiration, the absoluteExpiration
parameter must be NoAbsoluteExpiration.
- priority
- CacheItemPriority
CacheItemPriority 列挙体によって表現される、キャッシュ内に格納された他の項目に対するオブジェクトの相対コスト。The cost of the object relative to other items stored in the cache, as expressed by the CacheItemPriority enumeration. キャッシュからオブジェクトが削除されるときにこの値が使用されます。コストが低いオブジェクトは、コストが高いオブジェクトよりも先にキャッシュから削除されます。This value is used by the cache when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.
- onRemoveCallback
- CacheItemRemovedCallback
オブジェクトがキャッシュから削除されると呼び出されるデリゲート (指定されている場合)。A delegate that, if provided, will be called when an object is removed from the cache. このデリゲートを使用して、オブジェクトがキャッシュから削除されたことをアプリケーションに通知できます。You can use this to notify applications when their objects are deleted from the cache.
例外
key
パラメーターまたは value
パラメーターが null
です。The key
or value
parameter is null
.
slidingExpiration
パラメーターは、TimeSpan.Zero
未満、または 1 年を超える年数に設定します。You set the slidingExpiration
parameter to less than TimeSpan.Zero
or the equivalent of more than one year.
Cache
に追加しようとした項目に、absoluteExpiration
パラメーターと slidingExpiration
パラメーターの両方が設定されます。The absoluteExpiration
and slidingExpiration
parameters are both set for the item you are trying to add to the Cache
.
例
次の例は、アプリケーションのオブジェクトに項目を挿入するときに、優先順位の高い項目を割り当てる方法を示して Cache
います。The following example demonstrates how to assign an item high priority when you insert it into your application's Cache
object.
注意
デリゲートでこのメソッドを使用する方法の詳細については CacheItemRemovedCallback 、「 方法: キャッシュから項目が削除されたときにアプリケーションに通知する」を参照してください。For more information about how to use this method with the CacheItemRemovedCallback delegate, see How to: Notify an Application When an Item Is Removed from the Cache.
Cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High, onRemove);
Cache.Insert("DSN", connectionString, Nothing, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High, onRemove)
注釈
このメソッドは Cache
、同じパラメーターを持つ既存の項目を上書き key
します。This method will overwrite an existing Cache
item with the same key
parameter.
パラメーターとパラメーターの両方を設定することはできません absoluteExpiration
slidingExpiration
。You cannot set both the absoluteExpiration
and slidingExpiration
parameters. キャッシュ項目が特定の時刻に期限切れになるようにする場合は、 absoluteExpiration
パラメーターを特定の時刻に設定し、 slidingExpiration
パラメーターをに設定し NoSlidingExpiration ます。If you intend the cache item to expire at a specific time, you set the absoluteExpiration
parameter to the specific time, and the slidingExpiration
parameter to NoSlidingExpiration.
項目に最後にアクセスしてから一定の時間が経過した後にキャッシュ項目の有効期限が切れるようにするには、 slidingExpiration
パラメーターを有効期限の間隔に設定し、 absoluteExpiration
パラメーターをに設定し NoAbsoluteExpiration ます。If you intend the cache item to expire after a certain amount of time has passed since the last access to the item, you set the slidingExpiration
parameter to the expiration interval, and the absoluteExpiration
parameter to NoAbsoluteExpiration.
こちらもご覧ください
- DateTime
- TimeSpan
- CacheItemPriority
- CacheItemRemovedCallback
- アプリケーションデータのキャッシュCaching Application Data
適用対象
Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemUpdateCallback)
public:
void Insert(System::String ^ key, System::Object ^ value, System::Web::Caching::CacheDependency ^ dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, System::Web::Caching::CacheItemUpdateCallback ^ onUpdateCallback);
public void Insert (string key, object value, System.Web.Caching.CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, System.Web.Caching.CacheItemUpdateCallback onUpdateCallback);
member this.Insert : string * obj * System.Web.Caching.CacheDependency * DateTime * TimeSpan * System.Web.Caching.CacheItemUpdateCallback -> unit
Public Sub Insert (key As String, value As Object, dependencies As CacheDependency, absoluteExpiration As DateTime, slidingExpiration As TimeSpan, onUpdateCallback As CacheItemUpdateCallback)
パラメーター
- key
- String
オブジェクトの参照に使用されるキャッシュ キー。The cache key that is used to reference the object.
- value
- Object
キャッシュに挿入するオブジェクト。The object to insert into the cache.
- dependencies
- CacheDependency
項目のファイル依存関係またはキャッシュ キー依存関係。The file or cache key dependencies for the item. 依存関係が変化すると、オブジェクトは無効になり、キャッシュから削除されます。When any dependency changes, the object becomes invalid and is removed from the cache. 依存関係がない場合は、このパラメーターには null
が格納されます。If there are no dependencies, this parameter contains null
.
- absoluteExpiration
- DateTime
挿入されたオブジェクトが期限切れとなり、キャッシュから削除される時刻。The time at which the inserted object expires and is removed from the cache. 標準時間から夏時間への変更など、ローカル時間に関する問題を回避するには、このパラメーター値には Now ではなく UtcNow を使用してください。To avoid possible issues with local time such as changes from standard time to daylight saving time, use UtcNow instead of Now for this parameter value. 絶対有効期限を使用している場合は、slidingExpiration
パラメーターは NoSlidingExpiration に設定する必要があります。If you are using absolute expiration, the slidingExpiration
parameter must be set to NoSlidingExpiration.
- slidingExpiration
- TimeSpan
キャッシュされたオブジェクトが最後にアクセスされてからそのオブジェクトが期限切れになるまでの間隔。The interval between the time that the cached object was last accessed and the time at which that object expires. この値が 20 分に相当する場合、オブジェクトは、最後のアクセスから 20 分経過すると有効期限が切れ、キャッシュから削除されます。If this value is the equivalent of 20 minutes, the object will expire and be removed from the cache 20 minutes after it was last accessed. スライド式有効期限を使用している場合は、absoluteExpiration
パラメーターは NoAbsoluteExpiration に設定する必要があります。If you are using sliding expiration, the absoluteExpiration
parameter must be set to NoAbsoluteExpiration.
- onUpdateCallback
- CacheItemUpdateCallback
オブジェクトがキャッシュから削除される前に呼び出されるデリゲート。A delegate that will be called before the object is removed from the cache. これを使用して、キャッシュされた項目を更新し、キャッシュから削除されないようにできます。You can use this to update the cached item and ensure that it is not removed from the cache.
例外
key
、value
、または onUpdateCallback
パラメーターが null
です。The key
, value
, or onUpdateCallback
parameter is null
.
slidingExpiration
パラメーターは、TimeSpan.Zero
未満、または 1 年を超える年数に設定します。You set the slidingExpiration
parameter to less than TimeSpan.Zero
or the equivalent of more than one year.
Cache
に追加しようとした項目に、absoluteExpiration
パラメーターと slidingExpiration
パラメーターの両方が設定されます。The absoluteExpiration
and slidingExpiration
parameters are both set for the item you are trying to add to the Cache
.
- または --or-
dependencies
パラメーターは null
であり、absoluteExpiration
パラメーターは NoAbsoluteExpiration に設定され、slidingExpiration
パラメーターは NoSlidingExpiration に設定されます。The dependencies
parameter is null
, and the absoluteExpiration
parameter is set to NoAbsoluteExpiration, and the slidingExpiration
parameter is set to NoSlidingExpiration.
注釈
Insertメソッドを使用すると、キャッシュに新しい項目を挿入し、項目がキャッシュから削除される前に呼び出されるデリゲートを指定することができます。The Insert method enables you to insert a new item in the cache and provide a delegate that is called before the item is removed from the cache. デリゲートでは、キャッシュされた項目を更新して、キャッシュから削除されないようにすることができます。In the delegate, you can update the cached item and thereby prevent it from being removed from the cache.
このメソッドは Cache
、同じパラメーターを持つ既存の項目を上書き key
します。This method will overwrite an existing Cache
item with the same key
parameter.
パラメーターとパラメーターの両方を設定することはできません absoluteExpiration
slidingExpiration
。You cannot set both the absoluteExpiration
and slidingExpiration
parameters. キャッシュ項目が特定の時刻に期限切れになるようにする場合は、 absoluteExpiration
パラメーターを特定の時刻に設定し、 slidingExpiration
パラメーターをに設定し NoSlidingExpiration ます。If you intend the cache item to expire at a specific time, you set the absoluteExpiration
parameter to the specific time, and the slidingExpiration
parameter to NoSlidingExpiration.
項目が最後にアクセスされてからの設定期間が経過した後にキャッシュ項目の有効期限が切れるようにするには、 slidingExpiration
パラメーターを有効期限の間隔に設定し、 absoluteExpiration
パラメーターをに設定し NoAbsoluteExpiration ます。If you intend the cache item to expire after a set period of time since the item was last accessed, you set the slidingExpiration
parameter to the expiration interval, and you set the absoluteExpiration
parameter to NoAbsoluteExpiration.
こちらもご覧ください
適用対象
Insert(String, Object, CacheDependency)
public:
void Insert(System::String ^ key, System::Object ^ value, System::Web::Caching::CacheDependency ^ dependencies);
public void Insert (string key, object value, System.Web.Caching.CacheDependency dependencies);
member this.Insert : string * obj * System.Web.Caching.CacheDependency -> unit
Public Sub Insert (key As String, value As Object, dependencies As CacheDependency)
パラメーター
- key
- String
項目の識別に使用されるキャッシュ キー。The cache key used to identify the item.
- value
- Object
キャッシュに挿入するオブジェクト。The object to be inserted in the cache.
- dependencies
- CacheDependency
挿入されるオブジェクトのファイル依存関係またはキャッシュ キー依存関係。The file or cache key dependencies for the inserted object. 依存関係が変化すると、オブジェクトは無効になり、キャッシュから削除されます。When any dependency changes, the object becomes invalid and is removed from the cache. 依存関係がない場合は、このパラメーターには null
が格納されます。If there are no dependencies, this parameter contains null
.
例外
key
パラメーターまたは value
パラメーターが null
です。The key
or value
parameter is null
.
例
次の例は、XML 構成ファイルにキャッシュ依存関係がある項目をアプリケーションのキャッシュに挿入する方法を示しています。The following example demonstrates how to insert an item into an application's cache with a cache dependency on an XML configuration file.
Cache.Insert("DSN", connectionString, new CacheDependency(Server.MapPath("myconfig.xml")));
Cache.Insert("DSN", connectionString, New CacheDependency(Server.MapPath("myconfig.xml")))
注釈
このメソッドは、パラメーターと一致するキーを持つ既存のキャッシュ項目を上書き key
します。This method will overwrite an existing cache item whose key matches the key
parameter. メソッドのこのオーバーロードを使用してキャッシュに追加されたオブジェクト Insert
は、の優先度、 Default スライド式有効期限の値、 NoSlidingExpiration および絶対有効期限の値で挿入され NoAbsoluteExpiration ます。The object added to the cache using this overload of the Insert
method is inserted with a priority of Default, a sliding expiration value of NoSlidingExpiration, and an absolute expiration value of NoAbsoluteExpiration.
こちらもご覧ください
適用対象
Insert(String, Object)
項目の位置を参照するキャッシュ キーを指定し、CacheItemPriority 列挙体が提供する既定値を使用して、Cache オブジェクトに項目を挿入します。Inserts an item into the Cache object with a cache key to reference its location, using default values provided by the CacheItemPriority enumeration.
public:
void Insert(System::String ^ key, System::Object ^ value);
public void Insert (string key, object value);
member this.Insert : string * obj -> unit
Public Sub Insert (key As String, value As Object)
パラメーター
- key
- String
項目の参照に使用されるキャッシュ キー。The cache key used to reference the item.
- value
- Object
キャッシュに挿入するオブジェクト。The object to be inserted into the cache.
例外
key
パラメーターまたは value
パラメーターが null
です。The key
or value
parameter is null
.
例
次の例は、アプリケーションのキャッシュに項目を挿入する方法を示しています。The following example demonstrates how to insert an item into an application's cache.
Cache.Insert("DSN", connectionString);
Cache.Insert("DSN", connectionString)
注釈
このメソッドは、パラメーターと一致するキーを持つ既存のキャッシュ項目を上書き key
します。This method will overwrite an existing cache item whose key matches the key
parameter. メソッドのこのオーバーロードを使用して、キャッシュに追加されたオブジェクトは、 Insert
ファイルまたはキャッシュの依存関係、優先度、 Default スライド式有効期限の値、 NoSlidingExpiration およびの絶対有効期限の値を指定せずに挿入され NoAbsoluteExpiration ます。The object added to the cache using this overload of the Insert
method is inserted with no file or cache dependencies, a priority of Default, a sliding expiration value of NoSlidingExpiration, and an absolute expiration value of NoAbsoluteExpiration.
適用対象
Insert(String, Object, CacheDependency, DateTime, TimeSpan)
public:
void Insert(System::String ^ key, System::Object ^ value, System::Web::Caching::CacheDependency ^ dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration);
public void Insert (string key, object value, System.Web.Caching.CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration);
member this.Insert : string * obj * System.Web.Caching.CacheDependency * DateTime * TimeSpan -> unit
Public Sub Insert (key As String, value As Object, dependencies As CacheDependency, absoluteExpiration As DateTime, slidingExpiration As TimeSpan)
パラメーター
- key
- String
オブジェクトの参照に使用されるキャッシュ キー。The cache key used to reference the object.
- value
- Object
キャッシュに挿入するオブジェクト。The object to be inserted in the cache.
- dependencies
- CacheDependency
挿入されるオブジェクトのファイル依存関係またはキャッシュ キー依存関係。The file or cache key dependencies for the inserted object. 依存関係が変化すると、オブジェクトは無効になり、キャッシュから削除されます。When any dependency changes, the object becomes invalid and is removed from the cache. 依存関係がない場合は、このパラメーターには null
が格納されます。If there are no dependencies, this parameter contains null
.
- absoluteExpiration
- DateTime
挿入されたオブジェクトが期限切れとなり、キャッシュから削除される時刻。The time at which the inserted object expires and is removed from the cache. 標準時間から夏時間への変更など、ローカル時間に関する問題を回避するには、このパラメーター値には Now ではなく UtcNow を使用してください。To avoid possible issues with local time such as changes from standard time to daylight saving time, use UtcNow rather than Now for this parameter value. 絶対有効期限を使用している場合は、slidingExpiration
パラメーターは NoSlidingExpiration にする必要があります。If you are using absolute expiration, the slidingExpiration
parameter must be NoSlidingExpiration.
- slidingExpiration
- TimeSpan
挿入されたオブジェクトが最後にアクセスされた日時とそのオブジェクトの有効期限が切れる時刻の間隔です。The interval between the time the inserted object is last accessed and the time at which that object expires. この値が 20 分に相当する場合、オブジェクトは、最後のアクセスから 20 分経過すると有効期限が切れ、キャッシュから削除されます。If this value is the equivalent of 20 minutes, the object will expire and be removed from the cache 20 minutes after it was last accessed. スライド式有効期限を使用している場合は、absoluteExpiration
パラメーターは NoAbsoluteExpiration にする必要があります。If you are using sliding expiration, the absoluteExpiration
parameter must be NoAbsoluteExpiration.
例外
key
パラメーターまたは value
パラメーターが null
です。The key
or value
parameter is null
.
slidingExpiration
パラメーターは、TimeSpan.Zero
未満、または 1 年を超える年数に設定します。You set the slidingExpiration
parameter to less than TimeSpan.Zero
or the equivalent of more than one year.
Cache
に追加しようとした項目に、absoluteExpiration
パラメーターと slidingExpiration
パラメーターの両方が設定されます。The absoluteExpiration
and slidingExpiration
parameters are both set for the item you are trying to add to the Cache
.
例
次の例は、絶対有効期限を使用して、アプリケーションのキャッシュに項目を挿入する方法を示しています。The following example demonstrates how to insert an item into an application's cache with an absolute expiration.
注意
このメソッドの形式は Insert
キャッシュの依存関係をサポートしているため、項目に依存関係がない場合は、パラメーター dependency
null
Nothing
のコンマ区切りのリストで (Visual Basic) パラメーターをとして宣言する必要があります。Since this form of the Insert
method supports cache dependencies, if the item has no dependencies, you must declare the dependency
parameter as null
(Nothing
in Visual Basic) in the comma-delimited list of parameters.
Cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), Cache.NoSlidingExpiration);
Cache.Insert("DSN", connectionString, Nothing, DateTime.Now.AddMinutes(2), Cache.NoSlidingExpiration)
次の例は、スライド式有効期限を持つ項目をキャッシュに挿入する方法を示しています。The following example demonstrates how to insert an item into the cache with a sliding expiration.
Cache.Insert("DSN", connectionString, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(10));
Cache.Insert("DSN", connectionString, Nothing, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(10))
注釈
このメソッドは Cache
、同じパラメーターを持つ既存の項目を上書き key
します。This method will overwrite an existing Cache
item with the same key
parameter.
slidingExpiration
パラメーターがに設定されている場合 NoSlidingExpiration 、スライド式有効期限は無効になります。If the slidingExpiration
parameter is set to NoSlidingExpiration, sliding expiration is disabled. パラメーターをより大きい値に設定すると、パラメーターに slidingExpiration
Zero は、パラメーターに格納されて absoluteExpiration
いる値に加えてが設定され Now slidingExpiration
ます。If you set the slidingExpiration
parameter to greater than Zero, the absoluteExpiration
parameter is set to Now plus the value contained in the slidingExpiration
parameter. パラメーターで指定した時間が経過する前にキャッシュから項目が要求された場合、 absoluteExpiration
項目は再びキャッシュに配置され、 absoluteExpiration
さらに、 DateTime.Now
パラメーターに格納されている値に加算され slidingExpiration
ます。If the item is requested from the cache before the amount of time specified by the absoluteExpiration
parameter, the item will be placed in the cache again, and absoluteExpiration
will again be set to DateTime.Now
plus the value contained in the slidingExpiration
parameter. 項目がキャッシュから要求されていない場合、パラメーターの日付の前に、 absoluteExpiration
項目がキャッシュから削除されます。If the item is not requested from the cache before the date in the absoluteExpiration
parameter, the item is removed from the cache. Insert メソッドのこのオーバーロードを使用してキャッシュに追加された項目は、の優先度で挿入され Default ます。The item added to the cache using this overload of the insert method is inserted with a priority of Default.