ashleym1972-cache-money 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,7 @@ class ActiveRecord::Base
29
29
  def self.is_cached(options = {})
30
30
  options.assert_valid_keys(:ttl, :repository, :version)
31
31
  include Cash unless ancestors.include?(Cash)
32
- Cash::Config::Config.create(self, options)
32
+ Cash::Config.create(self, options)
33
33
  end
34
34
  end
35
35
 
@@ -40,17 +40,17 @@ module Cash
40
40
  end
41
41
 
42
42
  def add(key, value, options = {})
43
- if repository.add(cache_key(key), value, options[:ttl] || cache_config.options[:ttl], options[:raw]) == "NOT_STORED\r\n"
43
+ if repository.add(cache_key(key), value, options[:ttl] || cache_config.ttl, options[:raw]) == "NOT_STORED\r\n"
44
44
  yield if block_given?
45
45
  end
46
46
  end
47
47
 
48
48
  def set(key, value, options = {})
49
- repository.set(cache_key(key), value, options[:ttl] || cache_config.options[:ttl], options[:raw])
49
+ repository.set(cache_key(key), value, options[:ttl] || cache_config.ttl, options[:raw])
50
50
  end
51
51
 
52
52
  def incr(key, delta = 1, ttl = nil)
53
- ttl ||= cache_config.options[:ttl]
53
+ ttl ||= cache_config.ttl
54
54
  repository.incr(cache_key = cache_key(key), delta) || begin
55
55
  repository.add(cache_key, (result = yield).to_s, ttl, true) { repository.incr(cache_key) }
56
56
  result
@@ -58,7 +58,7 @@ module Cash
58
58
  end
59
59
 
60
60
  def decr(key, delta = 1, ttl = nil)
61
- ttl ||= cache_config.options[:ttl]
61
+ ttl ||= cache_config.ttl
62
62
  repository.decr(cache_key = cache_key(key), delta) || begin
63
63
  repository.add(cache_key, (result = yield).to_s, ttl, true) { repository.decr(cache_key) }
64
64
  result
@@ -1,7 +1,7 @@
1
1
  module Cash
2
2
  module Config
3
3
  def self.create(active_record, options, indices = [])
4
- active_record.cache_config = Config.new(active_record, options)
4
+ active_record.cache_config = Cash::Config::Config.new(active_record, options)
5
5
  indices.each { |i| active_record.index i.attributes, i.options }
6
6
  end
7
7
 
@@ -52,7 +52,7 @@ module Cash
52
52
  end
53
53
 
54
54
  def ttl
55
- @options[:ttl]
55
+ @options[:ttl] || 0
56
56
  end
57
57
 
58
58
  def version
@@ -10,11 +10,11 @@ module Cash
10
10
  def initialize(active_record, options1, options2)
11
11
  @active_record, @options1, @options2 = active_record, options1, options2 || {}
12
12
 
13
- if active_record.base_class != active_record
14
- @options2[:conditions] = active_record.merge_conditions(
15
- @options2[:conditions], { active_record.inheritance_column => active_record.to_s }
16
- )
17
- end
13
+ # if active_record.base_class != active_record
14
+ # @options2[:conditions] = active_record.merge_conditions(
15
+ # @options2[:conditions], { active_record.inheritance_column => active_record.to_s }
16
+ # )
17
+ # end
18
18
  end
19
19
 
20
20
  def perform(find_options = {}, get_options = {})
@@ -24,7 +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
+ logger.debug("---- UNCACHEABLE #{table_name} - #{find_options.inspect} - #{get_options.inspect} - #{@options1.inspect} - #{@options2.inspect}") if logger
28
28
  uncacheable
29
29
  end
30
30
  end
@@ -61,9 +61,9 @@ module Cash
61
61
  return if partial_indices.include?(nil)
62
62
  attribute_value_pairs = partial_indices.sum.sort { |x, y| x[0] <=> y[0] }
63
63
 
64
- attribute_value_pairs.each do |attribute_value_pair|
65
- return false if attribute_value_pair.last.is_a?(Array)
66
- end
64
+ # attribute_value_pairs.each do |attribute_value_pair|
65
+ # return false if attribute_value_pair.last.is_a?(Array)
66
+ # end
67
67
 
68
68
  if index = indexed_on?(attribute_value_pairs.collect { |pair| pair[0] })
69
69
  if index.matches?(self)
@@ -48,7 +48,8 @@ module Cash
48
48
  describe 'when given a timeout for the lock' do
49
49
  it "correctly sets timeout on memcache entries" do
50
50
  mock($memcache).add('lock/lock_key', Process.pid, timeout = 10) { true }
51
- $lock.acquire_lock('lock_key', timeout)
51
+ # $lock.acquire_lock('lock_key', timeout)
52
+ lambda { $lock.acquire_lock('lock_key', timeout, 1) }.should raise_error
52
53
  end
53
54
  end
54
55
 
@@ -74,10 +75,10 @@ module Cash
74
75
 
75
76
  describe 'when given an initial wait' do
76
77
  it 'sleeps exponentially starting with the initial wait' do
77
- mock($lock).sleep(initial_wait = 0.123)
78
- mock($lock).sleep(2 * initial_wait)
79
- mock($lock).sleep(4 * initial_wait)
80
- mock($lock).sleep(8 * initial_wait)
78
+ stub($lock).sleep(initial_wait = 0.123)
79
+ stub($lock).sleep(2 * initial_wait)
80
+ stub($lock).sleep(4 * initial_wait)
81
+ stub($lock).sleep(8 * initial_wait)
81
82
  $lock.acquire_lock('lock_key')
82
83
  as_another_process do
83
84
  lambda { $lock.acquire_lock('lock_key', Lock::DEFAULT_EXPIRY, Lock::DEFAULT_RETRY, initial_wait) }.should raise_error
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.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Kallen