ngmoco-cache-money 0.2.16 → 0.2.20

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cache_money.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'active_support'
2
- require 'active_support/all'
3
2
  require 'active_record'
4
3
 
5
4
  require 'cash/lock'
@@ -180,7 +180,7 @@ module Cash
180
180
  objects
181
181
  else
182
182
  cache_keys = objects.collect { |id| "id/#{id}" }
183
- objects = get(cache_keys, &method(:find_from_keys))
183
+ with_exclusive_scope(:find => {}) { objects = get(cache_keys, &method(:find_from_keys)) }
184
184
  convert_to_array(cache_keys, objects)
185
185
  end
186
186
  end
@@ -0,0 +1,31 @@
1
+ module Cash
2
+ module Relation
3
+ module CachedFinderMethods
4
+ def find_one_with_cache(id)
5
+ return find_one_without_cache unless is_cached
6
+
7
+ id = id.id if ActiveRecord::Base === id
8
+
9
+ cache_miss = false
10
+ result = @klass.get(id) do
11
+ cache_miss = true
12
+ find_one_without_cache(id)
13
+ end
14
+ @klass.set(id, result) if cache_miss && result
15
+ end
16
+
17
+ def find_some_with_cache(ids)
18
+ return find_some_without_cache unless is_cached
19
+
20
+ cache_miss = false
21
+ result = @klass.get(ids) do
22
+ cache_miss = true
23
+ find_some_without_cache(ids)
24
+ end
25
+ if cache_miss && result
26
+ result.each {|r| @klass.set(r.id, r) if r} if result.is_a?(Array)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
data/rails/init.rb CHANGED
@@ -31,12 +31,7 @@ else
31
31
  $cache = Cash::Transactional.new($local, $lock)
32
32
 
33
33
  # allow setting up caching on a per-model basis
34
- if memcache_config[:automatic_caching].to_s == 'false'
35
- Rails.logger.info "cache-money: global model caching disabled"
36
- class ActiveRecord::Base
37
- is_cached(false)
38
- end
39
- else
34
+ unless memcache_config[:automatic_caching].to_s == 'false'
40
35
  Rails.logger.info "cache-money: global model caching enabled"
41
36
  class ActiveRecord::Base
42
37
  is_cached(:repository => $cache)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngmoco-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 16
10
- version: 0.2.16
9
+ - 20
10
+ version: 0.2.20
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nick Kallen
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-09-02 00:00:00 -07:00
21
+ date: 2010-10-04 00:00:00 -07:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -83,6 +83,7 @@ files:
83
83
  - lib/cash/query/calculation.rb
84
84
  - lib/cash/query/primary_key.rb
85
85
  - lib/cash/query/select.rb
86
+ - lib/cash/relation/cached_finder_methods.rb
86
87
  - lib/cash/request.rb
87
88
  - lib/cash/transactional.rb
88
89
  - lib/cash/util/array.rb