選択のキャッシュ

□未翻訳

□翻訳中

■翻訳完了(細田謙二)

■レビュー(Omi Chiba)

選択のキャッシュ

selectメソッドはcache引数を取ります。これはデフォルトではNoneです。キャッシュの利用の際は、ここにタプルを設定する必要があります。このタプルの最初の要素はキャッシュモデルで(cache.ram、chace.diskなど)、第2の要素は秒単位の有効期限です。

The select method also takes a cache argument, which defaults to None. For caching purposes, it should be set to a tuple where the first element is the cache model (cache.ram, cache.disk, etc.), and the second element is the expiration time in seconds.

次の例では、前に定義したdb.logテーブルに対する選択をキャッシュするコントローラを示しています。実際の選択では、60秒間隔より頻繁にバックエンドのデータベースからデータを取り出すことはなく、cache.ramに結果を保存します。このコントローラへの次の呼び出しが最後のデータベースIOから60秒以内に発生する場合、cache.ramから前回のデータが単純に取り出されます。

In the following example, you see a controller that caches a select on the previously defined db.log table. The actual select fetches data from the back-end database no more frequently than once every 60 seconds and stores the result in cache.ram. If the next call to this controller occurs in less than 60 seconds since the last database IO, it simply fetches the previous data from cache.ram.

1.

2.

3.

def cache_db_select():

logs = db().select(db.log.ALL, cache=(cache.ram, 60))

return dict(logs=logs)

selectの結果は複雑で、pickle化できないオブジェクトです。したがって、これらはsessionに保存することはできず、ここで説明したもの以外はどの方法でもキャッシュすることはできません。

The results of a select are complex, un-pickleable objects; they cannot be stored in a session and cannot be cached in any other way than the one explained here.