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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cd8f3d3415798c444232ccdee444dc06f963f987958bf8837a1b34df44a0a72
4
- data.tar.gz: f1929127f81ef136d1a610ad0420d76ebc2d7d289d3abc2155d20303cc7e3e6c
3
+ metadata.gz: 1f47ca230c62c31bfaa2f488764ebb48b9e2aeefe611ba9fae8cd15d458a53e8
4
+ data.tar.gz: ed2839fb88a855bd60c92a3506fe367206b74db71479732009e6769af346c9a6
5
5
  SHA512:
6
- metadata.gz: 60dd0c5dfe91552e3f8ec55fdc3bf29fff67c6974e0be6c19d60db593e5c3a96cce9f206b0cc0f07d1749e0b1ac527ffceb1e7139a4bb145f655b56e1484412b
7
- data.tar.gz: 0fc2644e785fb6e0bb9be3c2ce154b20b9b7e8062f3ec9120830b8331f6b5173b8c53438bdf174ba15c5d39c77d279fd3cff3f92f1320a57ce0f0530b2cff256
6
+ metadata.gz: 8bf76a8198b3dc430c8ff5658da2d4889aa7344dad224241af7fd82c318100932a2d81582a946b942ab908ffc3e0e60a3dbe916999c4130fecc02e3f26bbd1ca
7
+ data.tar.gz: 31c5dc4eef93988cf1463827daf60b78bd19a0bf8e3ad536ee6cbe8f4f940b19ebe35c32b4027bf081e565f9c97e921336d9257f0d9a17a0d5be98786c648fdd
@@ -1,3 +1,3 @@
1
1
  module CachedCounts
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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: []