cache_with_settings 1.0.1 → 1.1.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 +8 -0
- data/lib/cache_with_settings.rb +5 -9
- data/lib/cache_with_settings/helpers/cache_helper.rb +11 -0
- data/lib/cache_with_settings/helpers/rendering_helper.rb +17 -0
- data/lib/cache_with_settings/railtie.rb +3 -2
- data/lib/cache_with_settings/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b76cecffa2413d7b9fef263126e442c308f5bceef78be1247625d9d389c89f71
|
4
|
+
data.tar.gz: 06da2bd8e0b1df6815ed1dbafd87ae78d0b7708c2112cb3b4570949b1278c2b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91791e4f60deffc829bcfb4f734e38bd5f7b8051d21a3e541794291157f255f07245ced1ce07cbc9edeb9b9934e6fe45760d55e80d4a8047897089fd70d3945b
|
7
|
+
data.tar.gz: 77384b41454b3043ce8be3135172608aba5e14a68fb198aad6d1941689adae05f65ba13303d2e58bf0fe43b5f4875d57168c44d15952c41ba04bd1c7e3b01631
|
data/README.md
CHANGED
@@ -33,6 +33,14 @@ end
|
|
33
33
|
|
34
34
|
That's it! Your template `cache` calls now automatically include the specified cache keys.
|
35
35
|
|
36
|
+
Collection caching is also supported. If you're rendering collections with `cached: true` your specified cache keys will automatically be included:
|
37
|
+
|
38
|
+
```erb
|
39
|
+
<%= render partial: "cities/city",
|
40
|
+
collection: @cities,
|
41
|
+
cached: true %>
|
42
|
+
```
|
43
|
+
|
36
44
|
## Installation
|
37
45
|
Add this line to your application's Gemfile:
|
38
46
|
|
data/lib/cache_with_settings.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "cache_with_settings/configuration"
|
4
|
+
require "cache_with_settings/helpers/cache_helper"
|
5
|
+
require "cache_with_settings/helpers/rendering_helper"
|
4
6
|
require "cache_with_settings/railtie"
|
5
7
|
|
6
8
|
module CacheWithSettings
|
7
9
|
module Helpers
|
8
|
-
|
9
|
-
super(cache_with_settings_compose_key(key), options) do
|
10
|
-
yield(block)
|
11
|
-
end
|
12
|
-
end
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
Array.wrap(key).concat(CacheWithSettings.cache_keys.call)
|
17
|
-
end
|
12
|
+
def self.compose_key(key)
|
13
|
+
Array.wrap(key).concat(CacheWithSettings.cache_keys.call)
|
18
14
|
end
|
19
15
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CacheWithSettings::Helpers
|
4
|
+
module RenderingHelper
|
5
|
+
def render(options = {}, locals = {}, &block)
|
6
|
+
if options.kind_of?(Hash) && options[:cached] == true
|
7
|
+
options[:cached] = -> object { CacheWithSettings.compose_key(object) }
|
8
|
+
end
|
9
|
+
|
10
|
+
if block_given?
|
11
|
+
super(options, locals) { yield(block) }
|
12
|
+
else
|
13
|
+
super(options, locals)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
module CacheWithSettings
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
|
-
initializer "
|
5
|
+
initializer "cache_with_settings.helpers" do
|
6
6
|
ActiveSupport.on_load :action_view do
|
7
|
-
ActionView::Base.send :include, CacheWithSettings::Helpers
|
7
|
+
ActionView::Base.send :include, CacheWithSettings::Helpers::CacheHelper
|
8
|
+
ActionView::Base.send :include, CacheWithSettings::Helpers::RenderingHelper
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_with_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- Rakefile
|
80
80
|
- lib/cache_with_settings.rb
|
81
81
|
- lib/cache_with_settings/configuration.rb
|
82
|
+
- lib/cache_with_settings/helpers/cache_helper.rb
|
83
|
+
- lib/cache_with_settings/helpers/rendering_helper.rb
|
82
84
|
- lib/cache_with_settings/railtie.rb
|
83
85
|
- lib/cache_with_settings/version.rb
|
84
86
|
- lib/tasks/cache_with_settings_tasks.rake
|