incrdecr_cached_counts 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cached_counts/version.rb +1 -1
- data/lib/cached_counts.rb +12 -0
- metadata +2 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f47ca230c62c31bfaa2f488764ebb48b9e2aeefe611ba9fae8cd15d458a53e8
|
4
|
+
data.tar.gz: ed2839fb88a855bd60c92a3506fe367206b74db71479732009e6769af346c9a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bf76a8198b3dc430c8ff5658da2d4889aa7344dad224241af7fd82c318100932a2d81582a946b942ab908ffc3e0e60a3dbe916999c4130fecc02e3f26bbd1ca
|
7
|
+
data.tar.gz: 31c5dc4eef93988cf1463827daf60b78bd19a0bf8e3ad536ee6cbe8f4f940b19ebe35c32b4027bf081e565f9c97e921336d9257f0d9a17a0d5be98786c648fdd
|
data/lib/cached_counts.rb
CHANGED
@@ -158,6 +158,18 @@ module CachedCounts
|
|
158
158
|
association_count_key(id, attribute_name, version)
|
159
159
|
end
|
160
160
|
|
161
|
+
# Try to fetch values for ids from the cache. If it's a miss return the default value
|
162
|
+
define_singleton_method "try_#{attr_name}_counts_for" do |ids, default=nil|
|
163
|
+
raw_result = Rails.cache.read_multi(*ids.map{|id| association_count_key(id, attribute_name, version)})
|
164
|
+
|
165
|
+
result = {}
|
166
|
+
ids.each do |id|
|
167
|
+
result[id] = raw_result[association_count_key(id, attribute_name, version)]&.to_i || default
|
168
|
+
end
|
169
|
+
|
170
|
+
result
|
171
|
+
end
|
172
|
+
|
161
173
|
define_singleton_method "#{attr_name}_count_for" do |id|
|
162
174
|
new({id: id}, without_protection: true).send("#{attr_name}_count")
|
163
175
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: incrdecr_cached_counts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Judd
|
@@ -177,13 +177,4 @@ rubygems_version: 3.0.3
|
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: A replacement for Rails' counter caches using memcached (via Dalli)
|
180
|
-
test_files:
|
181
|
-
- spec/caches_count_of_spec.rb
|
182
|
-
- spec/caches_count_where_spec.rb
|
183
|
-
- spec/database.yml
|
184
|
-
- spec/fixtures.rb
|
185
|
-
- spec/fixtures/department.rb
|
186
|
-
- spec/fixtures/following.rb
|
187
|
-
- spec/fixtures/university.rb
|
188
|
-
- spec/fixtures/user.rb
|
189
|
-
- spec/spec_helper.rb
|
180
|
+
test_files: []
|