第1章 $fh.cache
$fh.cache(options, callback);
クラウドアプリのキャッシュ層にある値を保存、読み込み、削除します。
デフォルトでは、キャッシュストアのメモリー上限は 1GB です。この上限に達すると、LRU (最も長く使われていない) アルゴリズムを使用してデータの削除を開始します。
キャッシュに値を保存する際に "expire" オプションが指定されていない場合は、その値はメモリー上限に達するまでキャッシュにとどまります。その後は、どの値を削除するかは LRU アルゴリズムで判断されます。
1.1. キャッシュオプションの管理
キャッシュのメモリー上限は Studio で管理が可能で、キャッシュストアのフラッシュもできます。これら 2 つのオプションは、リソース > [環境] > キャッシュ で設定できます。
キャッシュの最大サイズの設定は、環境内の全クラウドアプリに影響します。
1.2. 例
値をキャッシュに保存
var options = {
"act": "save",
"key": "foo", // The key associated with the object
"value": "bar", // The value to be cached, must be serializable
"expire": 60 // Expiry time in seconds. Optional
};
$fh.cache(options, function (err, res) {
if (err) return console.error(err.toString());
// res is the original cached object
console.log(res.toString());
});
キャッシュから値を読み込み
var options = {
"act": "load",
"key": "foo" // key to look for in cache
};
$fh.cache(options, function (err, res) {
if (err) return console.error(err.toString());
// res is the original cached object
console.log(res.toString());
});
キャッシュから値を削除
var options = {
"act": "remove",
"key": "foo" // key to look for in cache
};
$fh.cache(options, function (err, res) {
if (err) return console.error(err.toString());
// res is the removed cached object
console.log(res.toString());
});

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.