Kouhei Sutou
null+****@clear*****
Thu Jul 16 18:08:22 JST 2015
Kouhei Sutou 2015-07-16 18:08:22 +0900 (Thu, 16 Jul 2015) New Revision: 27b0dcbe563499e2afff6214022562cb909e02b5 https://github.com/groonga/groonga/commit/27b0dcbe563499e2afff6214022562cb909e02b5 Message: mrb: add cache mechanism It should be tested. Modified files: lib/mrb/scripts/command.rb Modified: lib/mrb/scripts/command.rb (+23 -1) =================================================================== --- lib/mrb/scripts/command.rb 2015-07-16 18:05:53 +0900 (c4e3e94) +++ lib/mrb/scripts/command.rb 2015-07-16 18:08:22 +0900 (5805943) @@ -20,9 +20,31 @@ module Groonga @writer ||= context.writer end + def cache_key(input) + nil + end + + def cache_output(key) + if key.nil? + yield + else + cache = Cache.current + cached_value = cache.fetch(key) + if cached_value + context.output = cached_value + cache.unref(key) + else + yield + cache.update(context.output) + end + end + end + def run_internal(input) begin - run_body(input) + cache_output(cache_key(input)) do + run_body(input) + end rescue GroongaError => groonga_error context.set_groonga_error(groonga_error) nil -------------- next part -------------- HTML����������������������������...다운로드