active_record_in_cache 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/lib/active_record_in_cache.rb +3 -2
- data/lib/active_record_in_cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28ebd1d181edc8f09c7e1235bf95de5332cb95ac1e61af23a9e76d97f2d92408
|
4
|
+
data.tar.gz: edbfe182ba09b12e88ea470e78dbb076381191e1e7bd86ed09b2f23e295cb136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70866938a12b79bca026b802e15c22d5016f5bfe33b99de372215b875bd8f2d2a862a411739145f06cdfcedc7d836be8b0ea9ff539400923078996e8a283214a
|
7
|
+
data.tar.gz: dc8d90b2af4ed7f928a2e3370395d03564a4991522c49d75b1afc340198626ad9ca658338e0764b0a34cbe8cc2c3666f7d41f1c4882cf5e98301cea0ef177e50
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/active_record_in_cache.svg)](https://badge.fury.io/rb/active_record_in_cache)
|
2
|
+
|
1
3
|
# ActiveRecordInCache
|
2
4
|
|
3
5
|
`ActiveRecordInCache` provides a method to execute SQL while automatically caching.
|
@@ -33,9 +35,14 @@ end
|
|
33
35
|
You can call the `in_cache` method at the end of the chain.
|
34
36
|
|
35
37
|
```ruby
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
Article.all.in_cache
|
39
|
+
# SELECT MAX("articles"."updated_at") FROM "articles"
|
40
|
+
# SELECT "articles".* FROM "articles"
|
41
|
+
#=> #<ActiveRecord::Relation ...>
|
42
|
+
|
43
|
+
Article.all.in_cache
|
44
|
+
# SELECT MAX("articles"."updated_at") FROM "articles"
|
45
|
+
#=> #<ActiveRecord::Relation ...>
|
39
46
|
```
|
40
47
|
|
41
48
|
Automatically check `maximum(:updated_at)` and use the cache if it exists.
|
@@ -36,8 +36,9 @@ module ActiveRecordInCache
|
|
36
36
|
#
|
37
37
|
# Article.all.in_cache(expires_in: 5.minutes)
|
38
38
|
#
|
39
|
-
def in_cache(column = :updated_at, options = {})
|
40
|
-
|
39
|
+
def in_cache(column = :updated_at, options = {}, &block)
|
40
|
+
value = block_given? ? all.instance_exec(&block) : all.maximum(column)
|
41
|
+
name = "#{all.to_sql}_#{value}"
|
41
42
|
Rails.cache.fetch(name, options) { all.to_a }
|
42
43
|
end
|
43
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_in_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sinsoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|