| Path: | lib/cache_manager.rb |
| Last Update: | 2007-12-21 07:59:26 +0900 |
$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}