public
Fork of defunkt/cache_fu
Description: Everyone's favorite memcached plugin for ActiveRecord.
Homepage: http://errtheblog.com
Clone URL: git://github.com/github/cache_fu.git
add memcached gem support
Quake Wang (author)
Wed Apr 30 21:32:41 -0700 2008
commit  3be030a826e5e7341e172c56258d115e429d32bc
tree    297bca0a0b197e5f5e1d17466da96de33a9b3a5e
parent  2f7cb0aceaf0239165e88898ded9575098dd4480
...
1
2
 
 
 
 
 
 
 
 
 
3
4
5
6
7
8
9
10
11
...
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
 
 
14
15
16
0
@@ -1,11 +1,16 @@
0
-require 'memcache'
0
-puts "=> You should be using the `memcache-client' gem. You're using RubyMemcache!" if Object.const_defined?(:RubyMemcache)
0
+begin
0
+ require 'memcache'
0
+rescue LoadError
0
+end
0
+
0
+begin
0
+ require 'memcached'
0
+rescue LoadError
0
+end
0
 
0
 begin
0
   require 'mem_cache_with_consistent_hashing'
0
 rescue LoadError
0
-else
0
- puts "=> MemCacheWithConsistentHashing being used."
0
 end
0
 
0
 require 'acts_as_cached'
...
4
5
6
 
7
8
9
...
4
5
6
7
8
9
10
0
@@ -4,6 +4,7 @@ require 'acts_as_cached/fragment_cache'
0
 require 'acts_as_cached/benchmarking'
0
 require 'acts_as_cached/disabled'
0
 require 'acts_as_cached/local_cache'
0
+require 'acts_as_cached/memcached_rails'
0
 
0
 module ActsAsCached
0
   @@config = {}
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
 
 
 
 
 
 
 
212
213
214
...
277
278
279
280
 
281
282
283
...
196
197
198
 
 
 
 
 
 
 
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
...
277
278
279
 
280
281
282
283
0
@@ -196,19 +196,19 @@ module ActsAsCached
0
 
0
     def swallow_or_raise_cache_errors(load_constants = false, &block)
0
       load_constants ? autoload_missing_constants(&block) : yield
0
- rescue NoMethodError, ArgumentError, MemCache::MemCacheError => error
0
- if ActsAsCached.config[:raise_errors]
0
- raise error
0
- else
0
- RAILS_DEFAULT_LOGGER.debug "MemCache Error: #{error.message}" rescue nil
0
- nil
0
- end
0
     rescue TypeError => error
0
       if error.to_s.include? 'Proc'
0
         raise MarshalError, "Most likely an association callback defined with a Proc is triggered, see http://ar.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html (Association Callbacks) for details on converting this to a method based callback"
0
       else
0
         raise error
0
       end
0
+ rescue Exception => error
0
+ if ActsAsCached.config[:raise_errors]
0
+ raise error
0
+ else
0
+ RAILS_DEFAULT_LOGGER.debug "MemCache Error: #{error.message}" rescue nil
0
+ nil
0
+ end
0
     end
0
 
0
     def autoload_missing_constants
0
@@ -277,7 +277,7 @@ module ActsAsCached
0
       set_cache
0
     end
0
 
0
- # Lourens Naudé
0
+ # Lourens Naud
0
     def expire_cache_with_associations(*associations_to_sweep)
0
       (Array(cache_options[:include]) + associations_to_sweep).flatten.uniq.compact.each do |assoc|
0
         Array(send(assoc)).compact.each { |item| item.expire_cache if item.respond_to?(:expire_cache) }
...
44
45
46
47
48
 
 
49
50
51
52
53
 
54
55
56
...
59
60
61
62
63
 
 
64
65
66
...
44
45
46
 
 
47
48
49
50
51
52
 
53
54
55
56
...
59
60
61
 
 
62
63
64
65
66
0
@@ -44,13 +44,13 @@ module ActsAsCached
0
       config[:namespace] << "-#{RAILS_ENV}"
0
 
0
       silence_warnings do
0
- Object.const_set :CACHE, memcache_klass.new(config)
0
- Object.const_set :SESSION_CACHE, memcache_klass.new(config) if config[:session_servers]
0
+ Object.const_set :CACHE, memcache_client(config)
0
+ Object.const_set :SESSION_CACHE, memcache_client(config) if config[:session_servers]
0
       end
0
 
0
       CACHE.servers = Array(config.delete(:servers))
0
       SESSION_CACHE.servers = Array(config[:session_servers]) if config[:session_servers]
0
-
0
+
0
       setup_session_store if config[:sessions]
0
       setup_fragment_store! if config[:fragments]
0
       setup_fast_hash! if config[:fast_hash]
0
@@ -59,8 +59,8 @@ module ActsAsCached
0
       CACHE
0
     end
0
 
0
- def memcache_klass
0
- Object.const_defined?(:MemCacheWithConsistentHashing) ? MemCacheWithConsistentHashing : MemCache
0
+ def memcache_client(config)
0
+ (config[:client] || "MemCache").constantize.new(config)
0
     end
0
 
0
     def setup_session_store

Comments

    No one has commented yet.