| Class | CacheManager |
| In: |
lib/cache_manager.rb
|
| Parent: | Object |
$Id: cache_manager.rb 120 2007-12-20 22:59:26Z tommy $
Copyright (C) 2007 TOMITA Masahiro
| Author: | TOMITA Masahiro <tommy@tmtm.org> |
| License: | Ruby‘s. see www.ruby-lang.org/en/LICENSE.txt |
$ make # make install
double = CacheManager.new do |key|
puts "invoked"
key * 2
end
double[1] # => 2, invoked
double[2] # => 4, invoked
double[1] # => 2, not invoked
three_obj_cache = CacheManager.new :limit=>3 do |key|
true
end
three_obj_cache[1]
three_obj_cache.cache # => {1=>true}
three_obj_cache[2]
three_obj_cache.cache # => {1=>true, 2=>true}
three_obj_cache[3]
three_obj_cache.cache # => {1=>true, 2=>true, 3=>true}
three_obj_cache[4]
three_obj_cache.cache # => {2=>true, 3=>true, 4=>true}
| opt: | オプション (Hash) |
| block: | Proc |
CacheManager を初期化する。 self#[key] 時に key に対応する値がキャッシュされていない場合は、block が呼び出され、その戻り値がキャッシュされる。
opt の有効なキーは次のとおり。