Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

retooling the way memcached store loads

  • Loading branch information...
commit 0acbdc667b5eab1d9e11759e7a735c6c3a48714c 1 parent c4d17d9
@actsasflinn authored
View
15 vendor/plugins/cache_contrib/init.rb
@@ -3,10 +3,10 @@
require 'memcache/timeout'
# Add a default expires_in value for cache stores that use it
-require 'active_support/cache/patches/expires_in_default'
+require 'active_support/cache/patches/default_expires_in'
# Fix to autoload missing classes with unmarshaling
-require 'active_support/cache/patches/read_with_autoload'
+require 'active_support/cache/patches/auto_load_missing_constants'
# Fix for fetch when cache_classes is false
require 'active_support/cache/patches/dependency_load_fix'
@@ -20,16 +20,11 @@ class Store
# it's an ugly workaround for the fact that plugins are loaded after initialize_cache
attr_writer :expires_in
- include DependencyLoadFix if ActiveSupport::Dependencies.mechanism == :load
+ include Patches::DependencyLoadFix if ActiveSupport::Dependencies.mechanism == :load
end
class MemCacheStore < Store
- include AutoLoadMissingConstants
- include DefaultExpiresIn
- end
-
- class MemcachedStore < Store
- include AutoLoadMissingConstants
- include DefaultExpiresIn
+ include Patches::AutoLoadMissingConstants
+ include Patches::DefaultExpiresIn
end
end
View
4 vendor/plugins/cache_contrib/lib/active_support/cache/memcached_store.rb
@@ -3,6 +3,10 @@
module ActiveSupport
module Cache
class MemcachedStore < Store
+ # TODO: Remove these if they ever make it into core
+ include ActiveSupport::Cache::Patches::AutoLoadMissingConstants
+ include ActiveSupport::Cache::Patches::DefaultExpiresIn
+
attr_reader :addresses
def initialize(*addresses)
View
27 vendor/plugins/cache_contrib/lib/active_support/cache/patches/auto_load_missing_constants.rb
@@ -0,0 +1,27 @@
+# Copyright (c) 2007 Chris Wanstrath
+module ActiveSupport
+ module Cache
+ module Patches
+ module AutoLoadMissingConstants
+ def self.included(base)
+ super
+ base.alias_method_chain :read, :auto_load
+ end
+
+ def autoload_missing_constants
+ yield
+ rescue ArgumentError, MemCache::MemCacheError => error
+ lazy_load ||= Hash.new { |hash, hash_key| hash[hash_key] = true; false }
+ if error.to_s[/undefined class|referred/] && !lazy_load[error.to_s.split.last.constantize] then retry
+ else raise error end
+ end
+
+ def read_with_auto_load(*args)
+ autoload_missing_constants do
+ read_without_auto_load(*args)
+ end
+ end
+ end
+ end
+ end
+end
View
17 vendor/plugins/cache_contrib/lib/active_support/cache/patches/default_expires_in.rb
@@ -0,0 +1,17 @@
+module ActiveSupport
+ module Cache
+ module Patches
+ module DefaultExpiresIn
+ def self.included(base)
+ super
+ base.send(:attr_accessor, :expires_in)
+ base.send(:alias_method_chain, :expires_in, :default_value)
+ end
+
+ def expires_in_with_default_value(options)
+ ((options && options[:expires_in]) || @expires_in).to_i
+ end
+ end
+ end
+ end
+end
View
16 vendor/plugins/cache_contrib/lib/active_support/cache/patches/dependency_load_fix.rb
@@ -5,14 +5,16 @@
#
module ActiveSupport
module Cache
- module DependencyLoadFix
- def self.included(base)
- super
- base.alias_method_chain :fetch, :dependency_load_fix
- end
+ module Patches
+ module DependencyLoadFix
+ def self.included(base)
+ super
+ base.alias_method_chain :fetch, :dependency_load_fix
+ end
- def fetch_with_dependency_load_fix(*arguments)
- block_given? ? yield : fetch_without_dependency_load_fix(*arguments)
+ def fetch_with_dependency_load_fix(*arguments)
+ block_given? ? yield : fetch_without_dependency_load_fix(*arguments)
+ end
end
end
end
View
14 vendor/plugins/cache_contrib/lib/active_support/cache/patches/expires_in_default.rb
@@ -1,14 +0,0 @@
-module ActiveSupport
- module Cache
- module DefaultExpiresIn
- def self.included(base)
- super
- base.send(:alias_method_chain, :expires_in, :default_value)
- end
-
- def expires_in_with_default_value(options)
- ((options && options[:expires_in]) || @expires_in).to_i
- end
- end
- end
-end
View
25 vendor/plugins/cache_contrib/lib/active_support/cache/patches/read_with_autoload.rb
@@ -1,25 +0,0 @@
-# Copyright (c) 2007 Chris Wanstrath
-module ActiveSupport
- module Cache
- module AutoLoadMissingConstants
- def self.included(base)
- super
- base.alias_method_chain :read, :auto_load
- end
-
- def autoload_missing_constants
- yield
- rescue ArgumentError, MemCache::MemCacheError => error
- lazy_load ||= Hash.new { |hash, hash_key| hash[hash_key] = true; false }
- if error.to_s[/undefined class|referred/] && !lazy_load[error.to_s.split.last.constantize] then retry
- else raise error end
- end
-
- def read_with_auto_load(*args)
- autoload_missing_constants do
- read_without_auto_load(*args)
- end
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.