cached_counts 0.2.5 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/lib/cached_counts/active_record_relation_methods.rb +10 -3
- data/lib/cached_counts/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 099b873eefb8c41c66af75ec703e7c8363044ff0
|
4
|
+
data.tar.gz: 26e85dc0d9b81e1147723aefd69c0c3480c55709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fbf0c99ac1d1b46df366a15badba40338febabc5268db6f8a978e4140b53956c53213c2b0d548e9839655a682c5e3823c443aec8964ed0cb97f86e00ee81c88
|
7
|
+
data.tar.gz: 080e32b056397811ad1749d8a108ec78ff9a37fd1000fd3f4d12b4fbb68bc4cd8a31094f09ac49eaf7788c5e7793a8c3e1de0e734e1625908fa695ea33e0cb7b
|
data/README.md
CHANGED
@@ -44,6 +44,25 @@ You can also use the non cached count on the class or scopes.
|
|
44
44
|
User.where(:admin => true).count_without_caching # => Runs a database lookup
|
45
45
|
```
|
46
46
|
|
47
|
+
## Usage with Rails
|
48
|
+
|
49
|
+
If you're using rails you can optionally disable the ovveriding of the `count` `size` and `lenght` methods by setting the `count_with_caching` configuration value.
|
50
|
+
You can do so in your application config like so:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
# config/application.rb
|
54
|
+
|
55
|
+
module MyApp
|
56
|
+
class Application < Rails::Application
|
57
|
+
#...
|
58
|
+
config.cache_counts_by_default = false
|
59
|
+
#...
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
Disabling the cache by default allows you to use `MyModel.count_with_caching` to return the cached count value.
|
65
|
+
|
47
66
|
## Clearing the cache
|
48
67
|
|
49
68
|
The counts cache is cleared for a model after save and after destroy.
|
@@ -5,9 +5,16 @@ module CachedCounts
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if defined?(Rails) && Rails.configuration.respond_to?(:cache_counts_by_default) && Rails.configuration.cache_counts_by_default
|
9
|
+
alias_method_chain :count, :caching
|
10
|
+
alias_method_chain :length, :caching
|
11
|
+
alias_method_chain :size, :caching
|
12
|
+
else
|
13
|
+
# Existing code calls count_without_caching, so just make it a no-op
|
14
|
+
alias_method :count_without_caching, :count
|
15
|
+
alias_method :length_without_caching, :length
|
16
|
+
alias_method :size_without_caching, :size
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
20
|
def count_with_caching(*args)
|