Permalink
Browse files

Adding Memcache#get monkeypatch, tests passing

  • Loading branch information...
1 parent 890a7b9 commit bf8728a056464a6a62e6296be147af3579cf67ed @winton committed Sep 7, 2011
@@ -37,8 +37,8 @@ def self.manual(cache, instance=nil)
url
end
- def self.match?(controller, fragment={})
- BackgroundCache::Config.match?(controller, fragment)
+ def self.match?(fragment={})
+ BackgroundCache::Config.match?(fragment)
end
private
@@ -49,10 +49,10 @@ def self.boot
end
end
-def BackgroundCache(path)
+def BackgroundCache(path, layout=false)
BackgroundCache.manual(
BackgroundCache::Config.build_cache(
- path.respond_to?(:keys) ? path : { :path => path, :layout => false }
+ path.respond_to?(:keys) ? path : { :path => path, :layout => layout }
)
)
end
@@ -65,17 +65,11 @@ def self.build_cache(options)
end
# Does controller and fragment match current cache?
- def self.match?(controller, fragment={})
- params = controller.params
- path = controller.request.env['REQUEST_URI']
+ def self.match?(fragment={})
cache = self.current_cache
cache &&
# Basic params match (action, controller, etc)
(
- (cache[:path] && cache[:path] == path) ||
- cache[:params] == params.symbolize_keys
- ) &&
- (
# No fragment specified
fragment.empty? ||
(
@@ -10,7 +10,7 @@ def self.included(base)
private
def read_fragment_with_background_cache(key, options=nil)
- if BackgroundCache.active? && BackgroundCache.match?(self, key)
+ if BackgroundCache.active? && BackgroundCache.match?(key)
RAILS_DEFAULT_LOGGER.info "Cached fragment busted (read_fragment method): #{key}"
nil
else
@@ -13,7 +13,7 @@ def cache_with_background_cache(name = {}, options = nil, &block)
cache = @controller.read_fragment(name, options)
match = (
BackgroundCache.active? &&
- BackgroundCache.match?(controller, name)
+ BackgroundCache.match?(name)
)
if !cache || match
pos = output_buffer.length
@@ -0,0 +1,20 @@
+module BackgroundCache
+ module Memcache
+
+ def self.included(base)
+ base.alias_method_chain :get, :background_cache
+ end
+
+ def get_with_background_cache(key, raw=false)
+ match = (
+ BackgroundCache.active? &&
+ BackgroundCache.match?(key)
+ )
+ if match
+ nil
+ else
+ get_without_background_cache(key, raw)
+ end
+ end
+ end
+end
View
@@ -1,5 +1,11 @@
+begin
+ require 'memcache'
+rescue LoadError
+end
+
require File.expand_path("#{File.dirname(__FILE__)}/../require")
Require.rails_init!
ActionController::Base.send(:include, BackgroundCache::Controller)
-ActionView::Helpers::CacheHelper.send(:include, BackgroundCache::Helper)
+ActionView::Helpers::CacheHelper.send(:include, BackgroundCache::Helper)
+::MemCache.send(:include, BackgroundCache::Memcache) if defined?(::MemCache)
View
@@ -3,6 +3,7 @@
require 'require'
Require do
+ gem :rails, '=2.3.10'
gem :require, '=0.2.7'
gem(:'rack-test', '=0.5.3') { require 'rack/test' }
gem(:rake, '=0.8.7') { require 'rake' }
@@ -28,6 +29,7 @@
require 'lib/background_cache/config'
require 'lib/background_cache/controller'
require 'lib/background_cache/helper'
+ require 'lib/background_cache/mem_cache'
end
rails_init { require 'lib/background_cache' }
@@ -39,6 +41,7 @@
end
spec_helper do
+ gem :rails
gem :'rack-test'
require 'require/spec_helper'
require 'pp'
@@ -1,7 +1,7 @@
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
-RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
+RAILS_GEM_VERSION = '2.3.10' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

0 comments on commit bf8728a

Please sign in to comment.