artirix_cache_service 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a01c290d04ff11dacda29d2c61f5ef7b8dece7d
4
- data.tar.gz: a39368fac963a4ecd34d344c54fdfcb1deee31c0
3
+ metadata.gz: 3e1719e6511906dbf2b6a809ce5908a1611619a4
4
+ data.tar.gz: 24a67f4e940d307c3ef8b9bd53b65aa4762e58bd
5
5
  SHA512:
6
- metadata.gz: cc6809a9de4d95d41c6e8a8799b60e93a3dd736551e4b4b9bb5cb52645889eff0afcafe3e6577795b1bed4efcb85c03a38f4ea4a543b92b07f5b3dfd268ff3eb
7
- data.tar.gz: 47803491fe5289afc35b01c82ac713fa568dda16ab5db3c850c5ac08fa3f81a9c9ad32ff8adceb77f399a2fed0a6821c87cd0185e5ac3cedaf22f1d9d8f38ec4
6
+ metadata.gz: 96b78b39ece2dfecaa199bc8a55c84e2aa2bf0ab6e1397c17e4d0494bb2c1045c3884e1eccc6ef712967291e46d0382360db75c6153834ffd294d9b0a24ea9ed
7
+ data.tar.gz: 87954784f67d284af6133f11e12b0f57407e3c4bc83b09ec9adf2b387a29ac38e5a4f68c33a88244512d0ef335cc758627a4118eabb5c6ac0bfa85cfbd737351
data/README.md CHANGED
@@ -248,6 +248,51 @@ redis_client = Redis.new redis_options
248
248
  redis_client.get 'my_app_prefix_myvar' # => 'paco'
249
249
  ```
250
250
 
251
+ ## View Helper
252
+
253
+ Calling `ArtirixCacheService.view_helper` we can access a module with a
254
+ `artirix_cache` helper method that acts as a proxy to normal Rails cache
255
+ view helper method.
256
+
257
+ It will use the Service to get the final key using the `.key` Service method,
258
+ and will load up the options to pass to `cache` method looking for the second
259
+ argument on the registered options (using `.options` Service method).
260
+
261
+ ```ruby
262
+ include ArtirixCacheService.view_helper
263
+
264
+
265
+ <%= artirix_cache :my_key, :registered_options_name, :arg1, request: request do %>
266
+ ...
267
+ <% end %>
268
+
269
+ # same as
270
+ <%= cache ArtirixCacheService.key(:my_key, :arg1, request: request),
271
+ ArtirixCacheService.options(:registered_options_name) do %>
272
+ ...
273
+ <% end %>
274
+ ```
275
+
276
+ First argument is required and it's the first argument to
277
+ `ArtirixCacheService.key` call. The 3rd and subsequent arguments are the extra
278
+ arguments in that call
279
+
280
+ The second argument will be used to call `.options`. We can supply an array of
281
+ possible option names to lookup (see `.options` method).
282
+
283
+
284
+ ```ruby
285
+ <%= artirix_cache :my_key, [:opts1, :otps2], :arg1, request: request do %>
286
+ ...
287
+ <% end %>
288
+
289
+ # same as
290
+ <%= cache ArtirixCacheService.key(:my_key, :arg1, request: request),
291
+ ArtirixCacheService.options(:opts1, :opts2) do %>
292
+ ...
293
+ <% end %>
294
+ ```
295
+
251
296
  ## Installation
252
297
 
253
298
  Add this line to your application's Gemfile:
@@ -277,6 +322,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/artiri
277
322
 
278
323
  # Changeset
279
324
 
325
+ ## v0.4.0
326
+
327
+ - View Helper with `artirix_cache` helper method
328
+
280
329
  ## v0.3.1
281
330
 
282
331
  - add request support
@@ -1,3 +1,3 @@
1
1
  module ArtirixCacheService
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -0,0 +1,19 @@
1
+ module ArtirixCacheService
2
+ module ViewHelper
3
+
4
+ def artirix_cache(key_prefix, options_name = [], *key_params, &block)
5
+ raise ArgumentError, 'key_prefix is required' unless key_prefix.present?
6
+
7
+ options = ArtirixCacheService.options *Array(options_name),
8
+ return_if_missing: :default
9
+
10
+ # if `disable_cache` in the options -> yield without caching
11
+ if options[:disable_cache]
12
+ yield
13
+ else
14
+ key = ArtirixCacheService.key key_prefix, *key_params
15
+ cache(key, options, &block)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,7 @@
1
1
  require 'active_support/all'
2
2
  require 'redis'
3
3
  require 'artirix_cache_service/version'
4
+ require 'artirix_cache_service/view_helper'
4
5
  require 'artirix_cache_service/key'
5
6
  require 'artirix_cache_service/options_service'
6
7
  require 'artirix_cache_service/variables_store_service'
@@ -25,6 +26,10 @@ module ArtirixCacheService
25
26
  to: :service
26
27
  end
27
28
 
29
+ def self.view_helper
30
+ ViewHelper
31
+ end
32
+
28
33
  def self.service
29
34
  @service ||= reload_service
30
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artirix_cache_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
@@ -119,6 +119,7 @@ files:
119
119
  - lib/artirix_cache_service/variables_stores/internal.rb
120
120
  - lib/artirix_cache_service/variables_stores/redis.rb
121
121
  - lib/artirix_cache_service/version.rb
122
+ - lib/artirix_cache_service/view_helper.rb
122
123
  homepage: https://github.com/artirix/artirix_cache_service
123
124
  licenses: []
124
125
  metadata: {}