seifertd-cache-money 0.2.7 → 0.2.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cash/accessor.rb CHANGED
@@ -9,21 +9,15 @@ module Cash
9
9
 
10
10
  module ClassMethods
11
11
  def fetch(keys, options = {}, &block)
12
- #puts "IN FETCH, KEYS: #{keys.inspect}, OPTIONS: #{options.inspect}, BLOCK: #{block.inspect}"
13
12
  case keys
14
13
  when Array
15
14
  keys = keys.collect { |key| cache_key(key) }
16
- #puts "KEYS ARE ARRAY #{keys.inspect}"
17
15
  hits = repository.get_multi(keys)
18
- #puts "HITS: #{hits.keys.inspect}"
19
16
  if (missed_keys = keys - hits.keys).any?
20
- #puts "MISSED KEYS: #{missed_keys.inspect}"
21
17
  missed_values = block.call(missed_keys)
22
- #puts "MISSED VALUES: #{missed_values.inspect}"
23
18
  # Stuff the newly hit stuff into the cache? Dubious?
24
19
  key_to_value = missed_keys.zip(Array(missed_values)).to_hash
25
20
  key_to_value.each do |new_key, new_val|
26
- #puts "CALLING SET #{new_key.inspect} => #{new_val.inspect}"
27
21
  repository.set(new_key, new_val, options[:ttl] || 0, options[:raw])
28
22
  end
29
23
  hits.merge!(key_to_value)
@@ -35,7 +29,6 @@ module Cash
35
29
  end
36
30
 
37
31
  def get(keys, options = {}, &block)
38
- #puts "IN GET, KEYS: #{keys.inspect}, OPTIONS: #{options.inspect}"
39
32
  case keys
40
33
  when Array
41
34
  fetch(keys, options, &block)
@@ -12,12 +12,9 @@ module Cash
12
12
  end
13
13
 
14
14
  def perform(find_options = {}, get_options = {})
15
- #puts "CALLING PEFORM: options1: #{@options1.inspect}, options2: #{@options2.inspect}, find_options: #{find_options.inspect}, get_options: #{get_options.inspect}"
16
15
  if cache_config = cacheable?(@options1, @options2, find_options)
17
16
  cache_keys, index = cache_keys(cache_config[0]), cache_config[1]
18
- #puts "CACHE KEYS: #{cache_keys.inspect}"
19
17
  misses, missed_keys, objects = hit_or_miss(cache_keys, index, get_options)
20
- #puts "MISSES: #{misses.inspect}, MISSED_KEYS: #{missed_keys.inspect}"
21
18
  format_results(cache_keys, choose_deserialized_objects_if_possible(missed_keys, cache_keys, misses, objects))
22
19
  else
23
20
  uncacheable
@@ -51,21 +48,12 @@ module Cash
51
48
 
52
49
  private
53
50
  def cacheable?(*optionss)
54
- #puts "CALLING CACHEABLE?: optionss: #{optionss.inspect}"
55
51
  optionss.each { |options| return unless safe_options_for_cache?(options) }
56
- #puts "ALL OPTIONS ARE SAFE FOR CACHE"
57
52
  partial_indices = optionss.collect { |options| attribute_value_pairs_for_conditions(options[:conditions]) }
58
- #puts "PARTIAL INDICES: #{partial_indices.inspect}"
59
53
  return if partial_indices.include?(nil)
60
- #puts "NONE OF THE PARTIAL INDICES INCLUDED NIL"
61
- #puts "SUM??? #{partial_indices.sum.inspect}"
62
54
  attribute_value_pairs = partial_indices.sum.sort { |x, y| x[0] <=> y[0] }
63
- #puts "ATTRIBUTE_VALUE_PAIRS: #{attribute_value_pairs.inspect}"
64
55
  if index = indexed_on?(attribute_value_pairs.collect { |pair| pair[0] })
65
- #puts "GOT A MATCHING INDEX: #{index.attributes.inspect}, CHECKING IF QUERY MATCHES"
66
- #puts "QUERY ORDER: #{order.inspect}, INDEX ORDER: #{index.order.inspect}"
67
56
  if index.matches?(self)
68
- #puts "QUERY MATCHES INDEX! YES!"
69
57
  [attribute_value_pairs, index]
70
58
  end
71
59
  end
@@ -122,16 +110,13 @@ module Cash
122
110
  end
123
111
 
124
112
  def indexed_on?(attributes)
125
- #puts "CHECKING IF AN INDEX MATCHES: #{attributes.inspect}"
126
113
  indices.detect do |index|
127
- #puts " -> INDEX ATTRIBUTES: #{index.attributes.inspect}"
128
114
  index == attributes
129
115
  end
130
116
  end
131
117
  alias_method :index_for, :indexed_on?
132
118
 
133
119
  def format_results(cache_keys, objects)
134
- #puts "IN FORMAT RESULTS"
135
120
  return objects if objects.blank?
136
121
 
137
122
  objects = convert_to_array(cache_keys, objects)
@@ -171,7 +156,9 @@ module Cash
171
156
 
172
157
  def find_from_keys(*missing_keys)
173
158
  missing_ids = Array(missing_keys).flatten.collect { |key| key.split('/')[2].to_i }
174
- find_from_ids_without_cache(missing_ids, {})
159
+ vals = find_from_ids_without_cache(missing_ids, {}).inject({}) {|h,obj| h[obj.id] = obj; h}
160
+ # Reorder according to input ids
161
+ return missing_ids.map{|id| vals[id]}
175
162
  end
176
163
  end
177
164
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seifertd-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Kallen