ashleym1972-cache-money 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/cash/config.rb CHANGED
@@ -27,7 +27,7 @@ module Cash
27
27
  end
28
28
 
29
29
  def index(attributes, options = {})
30
- options.assert_valid_keys(:ttl, :order, :limit, :buffer)
30
+ options.assert_valid_keys(:ttl, :order, :limit, :buffer, :order_column)
31
31
  (@cache_config.indices.unshift(Index.new(@cache_config, self, attributes, options))).uniq!
32
32
  end
33
33
 
data/lib/cash/index.rb CHANGED
@@ -2,7 +2,7 @@ module Cash
2
2
  class Index
3
3
  attr_reader :attributes, :options
4
4
  delegate :each, :hash, :to => :@attributes
5
- delegate :get, :set, :expire, :find_every_without_cache, :calculate_without_cache, :calculate_with_cache, :incr, :decr, :primary_key, :to => :@active_record
5
+ delegate :get, :set, :expire, :find_every_without_cache, :calculate_without_cache, :calculate_with_cache, :incr, :decr, :primary_key, :logger, :to => :@active_record
6
6
 
7
7
  DEFAULT_OPTIONS = { :ttl => 1.day }
8
8
 
@@ -64,6 +64,10 @@ module Cash
64
64
  def window
65
65
  limit && limit + buffer
66
66
  end
67
+
68
+ def order_column
69
+ options[:order_column] || 'id'
70
+ end
67
71
  end
68
72
  include Attributes
69
73
 
@@ -73,7 +77,7 @@ module Cash
73
77
 
74
78
  def matches?(query)
75
79
  query.calculation? ||
76
- (query.order == ['id', order] &&
80
+ (query.order == [order_column, order] &&
77
81
  (!limit || (query.limit && query.limit + query.offset <= limit)))
78
82
  end
79
83
 
data/lib/cash/local.rb CHANGED
@@ -8,7 +8,7 @@ module Cash
8
8
 
9
9
  def cache_locally
10
10
  @remote_cache = LocalBuffer.new(original_cache = @remote_cache)
11
- yield
11
+ yield if block_given?
12
12
  ensure
13
13
  @remote_cache = original_cache
14
14
  end
@@ -1,7 +1,7 @@
1
1
  module Cash
2
2
  module Query
3
3
  class Abstract
4
- delegate :with_exclusive_scope, :get, :table_name, :indices, :find_from_ids_without_cache, :cache_key, :columns_hash, :to => :@active_record
4
+ delegate :with_exclusive_scope, :get, :table_name, :indices, :find_from_ids_without_cache, :cache_key, :columns_hash, :logger, :to => :@active_record
5
5
 
6
6
  def self.perform(*args)
7
7
  new(*args).perform
@@ -24,6 +24,7 @@ module Cash
24
24
  misses, missed_keys, objects = hit_or_miss(cache_keys, index, get_options)
25
25
  format_results(cache_keys, choose_deserialized_objects_if_possible(missed_keys, cache_keys, misses, objects))
26
26
  else
27
+ logger.debug("---- UNCACHEABLE #{table_name} - #{find_options.inspect} - #{get_options.inspect} - #{@options1.inspect} - #{@options2.inspect}")
27
28
  uncacheable
28
29
  end
29
30
  end
@@ -94,7 +95,7 @@ module Cash
94
95
  when Hash
95
96
  conditions.to_a.collect { |key, value| [key.to_s, value] }
96
97
  when String
97
- parse_indices_from_condition(conditions)
98
+ parse_indices_from_condition(conditions.gsub('1 = 1 AND ', '')) #ignore unnecessary conditions
98
99
  when Array
99
100
  parse_indices_from_condition(*conditions)
100
101
  when NilClass
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ashleym1972-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Kallen