artirix_cache_service 0.4.0 → 0.5.0

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
  SHA1:
3
- metadata.gz: 3e1719e6511906dbf2b6a809ce5908a1611619a4
4
- data.tar.gz: 24a67f4e940d307c3ef8b9bd53b65aa4762e58bd
3
+ metadata.gz: 65a29d56ab01795d2127f62bccd84a00f4667dca
4
+ data.tar.gz: 5d64879751a1b97e376521f6a7c47bf4edaf6058
5
5
  SHA512:
6
- metadata.gz: 96b78b39ece2dfecaa199bc8a55c84e2aa2bf0ab6e1397c17e4d0494bb2c1045c3884e1eccc6ef712967291e46d0382360db75c6153834ffd294d9b0a24ea9ed
7
- data.tar.gz: 87954784f67d284af6133f11e12b0f57407e3c4bc83b09ec9adf2b387a29ac38e5a4f68c33a88244512d0ef335cc758627a4118eabb5c6ac0bfa85cfbd737351
6
+ metadata.gz: cbf5d72828d7eb04a0b90d2a6a6930433b55001885a8a8550f3e6e2e47abf9b9b366cb9b7b9c83a64cda748482ccc01ffb00024fcc02440ac84a0c428c67d535
7
+ data.tar.gz: bd80228958022cf34da234a228b464d1345cd4b3fa4a2e1894bfd45dfdc759ff028811a8beab95131c5923aaf3472c8f032c37b57786af06a59a817093d00317
data/README.md CHANGED
@@ -172,7 +172,7 @@ Note: we retrieve the variables as strings always, and return nil if `blank?`.
172
172
  ```ruby
173
173
 
174
174
  # some_view.html.erb
175
- <%= cache ArtirixCacheService.key(:my_key, variables: :classification) %>
175
+ <%= cache ArtirixCacheService.key(:my_key, variables: :my_var) %>
176
176
  ...
177
177
  <% end %>
178
178
 
@@ -209,6 +209,12 @@ ArtirixCacheService.variable_get(:my_var) { 990 } # => "990"
209
209
  ArtirixCacheService.variable_get :my_var # => "990"
210
210
  ```
211
211
 
212
+ We can list the variables that the service has currently access to with `.variables`
213
+
214
+ ```ruby
215
+ ArtirixCacheService.variables # => [ "my_var" ]
216
+ ```
217
+
212
218
  ### Variable Store
213
219
 
214
220
  by default (dev mode) the values are stored in an internal hash.
@@ -259,9 +265,10 @@ and will load up the options to pass to `cache` method looking for the second
259
265
  argument on the registered options (using `.options` Service method).
260
266
 
261
267
  ```ruby
268
+ # in ApplicationHelper
262
269
  include ArtirixCacheService.view_helper
263
270
 
264
-
271
+ # in the view
265
272
  <%= artirix_cache :my_key, :registered_options_name, :arg1, request: request do %>
266
273
  ...
267
274
  <% end %>
@@ -285,12 +292,29 @@ possible option names to lookup (see `.options` method).
285
292
  <%= artirix_cache :my_key, [:opts1, :otps2], :arg1, request: request do %>
286
293
  ...
287
294
  <% end %>
295
+ ```
288
296
 
289
- # same as
290
- <%= cache ArtirixCacheService.key(:my_key, :arg1, request: request),
291
- ArtirixCacheService.options(:opts1, :opts2) do %>
297
+ ### with `disable_cache: true` in the options
298
+
299
+ There is one important difference from using the `artirix_cache` view helper and
300
+ calling `cache` directly. If the options hash to be used has a truthy value on
301
+ `disable_cache` key, then it will `yield` directly and it will not call the
302
+ `cache` method
303
+
304
+ example:
305
+
306
+ ```ruby
307
+ # having:
308
+ ArtirixCacheService.options :options_with_disabled
309
+ # => { expires_in: 300, disable_cache: true }
310
+
311
+
312
+ # in the view
313
+ <%= artirix_cache :my_key, :options_with_disabled, :arg1, request: request do %>
292
314
  ...
293
315
  <% end %>
316
+
317
+ # will never call `cache` method, it will yield directly
294
318
  ```
295
319
 
296
320
  ## Installation
@@ -320,7 +344,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
320
344
  Bug reports and pull requests are welcome on GitHub at https://github.com/artirix/artirix_cache_service.
321
345
 
322
346
 
323
- # Changeset
347
+ # CHANGELOG
348
+
349
+ ## v0.5.0
350
+
351
+ - added `.variables`
324
352
 
325
353
  ## v0.4.0
326
354
 
@@ -337,4 +365,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/artiri
337
365
  ## v0.2.0
338
366
 
339
367
  - removed `ArtirixCacheService.config_params` support, now using `register_key_prefix` method
340
- - add `options` support
368
+ - add `options` support
@@ -22,7 +22,7 @@ module ArtirixCacheService
22
22
  :variables_store, :register_variables_store, :reload_variables_store,
23
23
  :redis_options, :redis_options=,
24
24
  :redis_variable_prefix, :redis_variable_prefix=,
25
- :variable_set, :variable_get,
25
+ :variable_set, :variable_get, :variables,
26
26
  to: :service
27
27
  end
28
28
 
@@ -25,7 +25,7 @@ module ArtirixCacheService
25
25
  delegate :register_variables_store, :variables_store, :reload_variables_store,
26
26
  :redis_options, :redis_options=,
27
27
  :redis_variable_prefix, :redis_variable_prefix=,
28
- :variable_get, :variable_set,
28
+ :variable_get, :variable_set, :variables,
29
29
  to: :variables_store_service
30
30
 
31
31
  private
@@ -25,7 +25,7 @@ module ArtirixCacheService
25
25
  @variables_store ||= build_internal
26
26
  end
27
27
 
28
- delegate :variable_get, :variable_set, :type, to: :variables_store
28
+ delegate :variable_get, :variable_set, :variables, :type, to: :variables_store
29
29
 
30
30
  private
31
31
 
@@ -2,6 +2,10 @@ module ArtirixCacheService
2
2
  module VariablesStores
3
3
  class Base
4
4
 
5
+ def variables
6
+ raise 'abstract method not overridden'
7
+ end
8
+
5
9
  def variable_get(given_key, &block)
6
10
  key = given_key.to_sym
7
11
  val = retrieve(key).presence
@@ -5,6 +5,10 @@ module ArtirixCacheService
5
5
  :internal
6
6
  end
7
7
 
8
+ def variables
9
+ map.keys.map &:to_s
10
+ end
11
+
8
12
  private
9
13
 
10
14
  def retrieve(key)
@@ -2,6 +2,9 @@ module ArtirixCacheService
2
2
  module VariablesStores
3
3
  class Redis < Base
4
4
 
5
+ EMPTY_STRING = ''.freeze
6
+ WILDCARD = '*'.freeze
7
+
5
8
  attr_reader :redis_variable_prefix
6
9
 
7
10
  def type
@@ -13,8 +16,16 @@ module ArtirixCacheService
13
16
  @redis_options = redis_options
14
17
  end
15
18
 
19
+ def variables
20
+ list.map { |key| clean_listed_variable key }
21
+ end
22
+
16
23
  private
17
24
 
25
+ def list
26
+ redis.keys(complete_key(WILDCARD))
27
+ end
28
+
18
29
  def retrieve(key)
19
30
  redis.get(complete_key(key))
20
31
  end
@@ -27,6 +38,14 @@ module ArtirixCacheService
27
38
  "#{redis_variable_prefix}_#{key}"
28
39
  end
29
40
 
41
+ def clean_listed_variable(key)
42
+ key.sub clean_listed_regex, EMPTY_STRING
43
+ end
44
+
45
+ def clean_listed_regex
46
+ @clean_listed_regex ||= /^#{redis_variable_prefix}_/
47
+ end
48
+
30
49
  def redis
31
50
  @redis ||= ::Redis.new @redis_options
32
51
  end
@@ -1,3 +1,3 @@
1
1
  module ArtirixCacheService
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artirix_cache_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-08 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport