Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Commit

Permalink
Updated GRIT's request cache
Browse files Browse the repository at this point in the history
Minor updates to core
  • Loading branch information
Dimitrij Denissenko committed Sep 19, 2009
1 parent bf369cc commit 6111c30
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -8,3 +8,4 @@ require 'rake/testtask'
require 'rake/rdoctask' require 'rake/rdoctask'


require 'tasks/rails' require 'tasks/rails'
require 'retrospectiva/extension_manager/rake_tasks'
4 changes: 3 additions & 1 deletion lib/retrospectiva/core_ext.rb
@@ -1,7 +1,9 @@
require 'erb'

YAML.module_eval do YAML.module_eval do
def self.load_configuration(path, default_value) def self.load_configuration(path, default_value)
path = "#{path}.default" unless File.exist?(path) 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
end end


Expand Down
1 change: 1 addition & 0 deletions lib/retrospectiva/extension_manager/extension_installer.rb
@@ -1,4 +1,5 @@
require 'tempfile' require 'tempfile'
require 'yaml'


module Retrospectiva module Retrospectiva
module ExtensionManager module ExtensionManager
Expand Down
6 changes: 6 additions & 0 deletions lib/retrospectiva/extension_manager/rake_tasks.rb
@@ -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
39 changes: 20 additions & 19 deletions vendor/plugins/grit/lib/grit/caching.rb
@@ -1,42 +1,43 @@
module Grit module Grit
@@result_cache = {}
@@cache_enabled = false


class << self class << self

attr_accessor :result_cache, :cache_enabled


def cache_enabled?
@@cache_enabled == true
end

def result_cache
@@result_cache
end

def cache def cache
old_value = self.cache_enabled old_value = @@cache_enabled
self.cache_enabled = true @@cache_enabled = true
yield yield
ensure ensure
self.cache_enabled = old_value @@cache_enabled = old_value
self.result_cache.clear @@result_cache.clear
end end


end end

self.cache_enabled = false
self.result_cache = {}

module ResultCache


class Git

def execute_with_cache(call, timeout = nil) 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] result = Grit.result_cache[call]
if result if result
Grit.logger.debug " Grit 0.0ms #{call}" Grit.logger.debug " Grit (0.0ms CACHED) #{call}"
result result
else else
Grit.result_cache[call] = execute_without_cache(call, timeout) Grit.result_cache[call] = execute_without_cache(call, timeout)
end end
end end

end

class Git
include ResultCache
alias_method :execute_without_cache, :execute alias_method :execute_without_cache, :execute
alias_method :execute, :execute_with_cache alias_method :execute, :execute_with_cache

end end
end end

0 comments on commit 6111c30

Please sign in to comment.