artirix_cache_service 0.4.0 → 0.5.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 +4 -4
- data/README.md +35 -7
- data/lib/artirix_cache_service.rb +1 -1
- data/lib/artirix_cache_service/service.rb +1 -1
- data/lib/artirix_cache_service/variables_store_service.rb +1 -1
- data/lib/artirix_cache_service/variables_stores/base.rb +4 -0
- data/lib/artirix_cache_service/variables_stores/internal.rb +4 -0
- data/lib/artirix_cache_service/variables_stores/redis.rb +19 -0
- data/lib/artirix_cache_service/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65a29d56ab01795d2127f62bccd84a00f4667dca
|
4
|
+
data.tar.gz: 5d64879751a1b97e376521f6a7c47bf4edaf6058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: :
|
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
|
-
|
290
|
-
|
291
|
-
|
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
|
-
#
|
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
|
@@ -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
|
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
|
+
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-
|
11
|
+
date: 2015-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|