cached_counts 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 39cbb1ba185ecbe803bd6548f95a8cb97c7e3b88
4
+ data.tar.gz: be16dc5bf9dea10b397e9be394ec698ba6c0fc05
5
+ SHA512:
6
+ metadata.gz: 888fb3234b3e787ad7761c6181c05a106c0a58248595f5a1a4f6d86595bab5fc9dfad19b6527101501f996a9f9905e6ebca1d4e6e4b24fda0aaec35390c7271a
7
+ data.tar.gz: d6cdcfdd27bbb3efa8cf31529c8b771c31f9a51964c46b519d1798ebff0c769ac72c520da32b3894caf80017187d727a5f548902097dc3057f0ebcb1d9c96878
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rake'
4
+
3
5
  gemspec
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ puts "rspec no available"
8
+ end
9
+
10
+ task :default => ['spec']
@@ -2,15 +2,17 @@ module CachedCounts
2
2
  class Cache
3
3
  def initialize(scope)
4
4
  @scope = scope
5
+ @args = []
5
6
  end
6
7
 
7
8
  def count(*args)
8
- cached_count || uncached_count(*args)
9
+ @args = args
10
+ cached_count || uncached_count
9
11
  end
10
12
 
11
13
  # Clear out any count caches which have SQL that includes the scopes table
12
14
  def clear
13
- invalid_keys = all_keys.select { |key| key.include?(@scope.table_name.downcase.singularize) }
15
+ invalid_keys = all_keys.select { |key| key.include?(@scope.table_name.downcase) }
14
16
  invalid_keys.each { |key| Rails.cache.delete(key) }
15
17
 
16
18
  Rails.cache.write(list_key, all_keys - invalid_keys)
@@ -24,8 +26,8 @@ module CachedCounts
24
26
  end
25
27
  end
26
28
 
27
- def uncached_count(*args)
28
- @scope.count_without_caching(*args).tap do |count|
29
+ def uncached_count
30
+ @scope.count_without_caching(*@args).tap do |count|
29
31
  Rails.cache.write(current_key, count)
30
32
  Rails.cache.write(list_key, all_keys + [current_key])
31
33
  end
@@ -40,7 +42,7 @@ module CachedCounts
40
42
  end
41
43
 
42
44
  def current_key
43
- "cached_counts::#{@scope.to_sql.downcase}"
45
+ "cached_counts::#{@scope.to_sql.downcase}::#{@args}"
44
46
  end
45
47
  end
46
48
  end
@@ -1,3 +1,3 @@
1
1
  module CachedCounts
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -18,13 +18,23 @@ describe CachedCounts::Cache do
18
18
  scope.should_receive(:count_without_caching).with('first').and_return(5)
19
19
  cache.count('first').should == 5
20
20
  end
21
+
22
+ it 'uses a different cache for different option values' do
23
+ scope.should_receive(:count_without_caching).with('first').and_return(5)
24
+ scope.should_receive(:count_without_caching).with('second').and_return(10)
25
+ scope.should_receive(:count_without_caching).with('second', { :hi => 'there' }).and_return(12)
26
+
27
+ cache.count('first').should == 5
28
+ cache.count('second').should == 10
29
+ cache.count('second', { :hi => 'there' }).should == 12
30
+ end
21
31
  end
22
32
 
23
33
  context 'when the cached key is blank' do
24
34
  before do
25
35
  scope.stub(:count_without_caching => 5)
26
36
  cache.count
27
- Rails.cache.write(cache.send(:current_key), nil)
37
+ Rails.cache.delete(cache.send(:current_key))
28
38
  end
29
39
 
30
40
  it 'returns the real count' do
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cached_counts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.2.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mario Visic
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-23 00:00:00.000000000 Z
11
+ date: 2013-03-31 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: activesupport
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: activerecord
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rails
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '3.2'
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '3.2'
94
83
  description: Speed up ActiveRecord counting with caching
@@ -121,27 +110,26 @@ files:
121
110
  homepage: https://github.com/desktoppr/cached_counts
122
111
  licenses:
123
112
  - MIT
113
+ metadata: {}
124
114
  post_install_message:
125
115
  rdoc_options: []
126
116
  require_paths:
127
117
  - lib
128
118
  required_ruby_version: !ruby/object:Gem::Requirement
129
- none: false
130
119
  requirements:
131
- - - ! '>='
120
+ - - '>='
132
121
  - !ruby/object:Gem::Version
133
122
  version: '0'
134
123
  required_rubygems_version: !ruby/object:Gem::Requirement
135
- none: false
136
124
  requirements:
137
- - - ! '>='
125
+ - - '>='
138
126
  - !ruby/object:Gem::Version
139
127
  version: '0'
140
128
  requirements: []
141
129
  rubyforge_project:
142
- rubygems_version: 1.8.24
130
+ rubygems_version: 2.0.0
143
131
  signing_key:
144
- specification_version: 3
132
+ specification_version: 4
145
133
  summary: Uses the Rails cache to store cached counts for active record models as well
146
134
  as models with scopes
147
135
  test_files: