キャッシュへのデータ挿入
put() メソッドを使用してキャッシュ要素を挿入できます。これにより、Catalyst プロジェクト内の既存のキャッシュセグメントにキーと値のペアを挿入できます。キー名とキー値は String 型で、メソッドの引数として渡します。
オプションでキャッシュ要素の有効期限を渡すこともできます。値を渡さない場合、有効期限はデフォルトで 48 時間に設定されます。
以下のコードスニペットで使用している segment の参照は、以前作成したセグメントインスタンスです。ここで返される Promise は JSON オブジェクトに解決されます。
copy
//Insert Cache by passing the key-value pair
let cache = app.cache();
let segment = cache.segment();
let cachePromise = segment.put('Name', 'Linda McCartney',1); //Expiry time for cache in hours
cachePromise.then((entity) => { console.log(entity); });
各バージョンで受信するサンプルレスポンスを以下に示します:
Node JS
copy
{
cache_name: "Last_Name",
cache_value: "Smith",
project_details: { project_name: "AlienCity", id: "2136000000007733" },
segment_details: { segment_name: "DataStore", id: "2136000000008572" },
expires_in: "Aug 18, 2021 06:46 PM",
expiry_in_hours: "48",
ttl_in_milliseconds: "172800000"
}
{
cache_name: "Last_Name",
cache_value: "Smith",
project_details: { project_name: "AlienCity", id: 2136000000007733 },
segment_details: { segment_name: "DataStore", id: 2136000000008572 },
expires_in: "Aug 18, 2021 06:45 PM",
expiry_in_hours: 48,
ttl_in_milliseconds: 172800000
}
最終更新日 2026-02-23 18:09:41 +0530 IST
Yes
No
Send your feedback to us
Skip
Submit