Permalink
Browse files

Updated GRIT's request cache

Minor updates to core
  • Loading branch information...
Dimitrij Denissenko
Dimitrij Denissenko committed Sep 19, 2009
1 parent bf369cc commit 6111c302945b401c85bbd861f7181d536f6b8c2d
View
@@ -8,3 +8,4 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
require 'retrospectiva/extension_manager/rake_tasks'
@@ -1,7 +1,9 @@
require 'erb'
YAML.module_eval do
def self.load_configuration(path, default_value)
path = "#{path}.default" unless File.exist?(path)
(YAML.load_file(path) rescue default_value) || default_value
(YAML.load(ERB.new(File.read(path)).result) rescue default_value) || default_value
end
end
@@ -1,4 +1,5 @@
require 'tempfile'
require 'yaml'
module Retrospectiva
module ExtensionManager
@@ -0,0 +1,6 @@
require 'retrospectiva/core_ext'
require 'retrospectiva/extension_manager/extension_installer'
Retrospectiva::ExtensionManager::ExtensionInstaller.installed_extension_names.each do |name|
Dir["#{RAILS_ROOT}/extensions/#{name}/**/*.rake"].sort.each { |ext| load ext }
end
@@ -1,42 +1,43 @@
module Grit
@@result_cache = {}
@@cache_enabled = false
class << self
attr_accessor :result_cache, :cache_enabled
def cache_enabled?
@@cache_enabled == true
end
def result_cache
@@result_cache
end
def cache
old_value = self.cache_enabled
self.cache_enabled = true
old_value = @@cache_enabled
@@cache_enabled = true
yield
ensure
self.cache_enabled = old_value
self.result_cache.clear
end
@@cache_enabled = old_value
@@result_cache.clear
end
end
self.cache_enabled = false
self.result_cache = {}
module ResultCache
class Git
def execute_with_cache(call, timeout = nil)
return execute_without_cache(call, timeout) unless Grit.cache_enabled
return execute_without_cache(call, timeout) unless Grit.cache_enabled?
result = Grit.result_cache[call]
if result
Grit.logger.debug " Grit 0.0ms #{call}"
Grit.logger.debug " Grit (0.0ms CACHED) #{call}"
result
else
Grit.result_cache[call] = execute_without_cache(call, timeout)
end
end
end
class Git
include ResultCache
alias_method :execute_without_cache, :execute
alias_method :execute, :execute_with_cache
end
end

0 comments on commit 6111c30

Please sign in to comment.