cached_counts 0.1.4 → 0.2.0

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.
@@ -15,9 +15,13 @@ module CachedCounts
15
15
  end
16
16
  end
17
17
 
18
+ # Clear out any count caches which have SQL that includes the scopes table
18
19
  def clear
19
- all_keys.each { |key| Rails.cache.delete(key) }
20
- Rails.cache.delete(list_key)
20
+ keys = all_keys
21
+ invalid_keys = keys.select { |key| key.include?(@scope.table_name.downcase.singularize) }
22
+ invalid_keys.each { |key| Rails.cache.delete(key) }
23
+
24
+ Rails.cache.write(list_key, keys - invalid_keys)
21
25
  end
22
26
 
23
27
  private
@@ -27,11 +31,11 @@ module CachedCounts
27
31
  end
28
32
 
29
33
  def list_key
30
- "count:#{@scope.model_name.underscore}::keys"
34
+ "cached_counts::keys"
31
35
  end
32
36
 
33
37
  def current_key
34
- "count:#{@scope.model_name.underscore}::cached_count::#{@scope.to_sql.hash}"
38
+ "cached_counts::#{@scope.to_sql.downcase}"
35
39
  end
36
40
  end
37
41
  end
@@ -1,3 +1,3 @@
1
1
  module CachedCounts
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -35,7 +35,7 @@ describe CachedCounts::Cache do
35
35
  let(:new_scope) { Scope.new('Cat') }
36
36
  let(:same_scope) { Scope.new('Cat') }
37
37
 
38
- before { new_scope.stub(:to_sql => 'new-sql-here') }
38
+ before { new_scope.stub(:to_sql => 'select * from cats where name = "bob"') }
39
39
 
40
40
  it 'uses a different cache for different to_sql values' do
41
41
  scope.stub(:count_without_caching => 5)
@@ -1,7 +1,7 @@
1
1
  class Scope
2
- attr_accessor :model_name, :to_sql
3
- def initialize(model_name)
4
- @model_name = model_name
5
- @to_sql = 'sql'
2
+ attr_accessor :table_name, :to_sql
3
+ def initialize(table_name)
4
+ @table_name = table_name
5
+ @to_sql = "select * from #{table_name}"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cached_counts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-17 00:00:00.000000000 Z
12
+ date: 2013-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake