Class: CachedCounts::Cache
- Inherits:
-
Object
- Object
- CachedCounts::Cache
- Defined in:
- lib/cached_counts/cache.rb
Instance Method Summary collapse
-
#clear ⇒ Object
Clear out any count caches which have SQL that includes the scopes table.
- #count(*args) ⇒ Object
-
#initialize(scope) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(scope) ⇒ Cache
3 4 5 6 |
# File 'lib/cached_counts/cache.rb', line 3 def initialize(scope) @scope = scope @args = [] end |
Instance Method Details
#clear ⇒ Object
Clear out any count caches which have SQL that includes the scopes table
14 15 16 17 18 19 |
# File 'lib/cached_counts/cache.rb', line 14 def clear invalid_keys = all_keys.select { |key| key.include?(@scope.table_name.downcase) } invalid_keys.each { |key| Rails.cache.delete(key) } Rails.cache.write(list_key, all_keys - invalid_keys) end |
#count(*args) ⇒ Object
8 9 10 11 |
# File 'lib/cached_counts/cache.rb', line 8 def count(*args) @args = args cached_count || uncached_count end |