artirix_cache_service 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -3
- data/lib/artirix_cache_service/key.rb +21 -7
- data/lib/artirix_cache_service/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a01c290d04ff11dacda29d2c61f5ef7b8dece7d
|
4
|
+
data.tar.gz: a39368fac963a4ecd34d344c54fdfcb1deee31c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc6809a9de4d95d41c6e8a8799b60e93a3dd736551e4b4b9bb5cb52645889eff0afcafe3e6577795b1bed4efcb85c03a38f4ea4a543b92b07f5b3dfd268ff3eb
|
7
|
+
data.tar.gz: 47803491fe5289afc35b01c82ac713fa568dda16ab5db3c850c5ac08fa3f81a9c9ad32ff8adceb77f399a2fed0a6821c87cd0185e5ac3cedaf22f1d9d8f38ec4
|
data/README.md
CHANGED
@@ -6,9 +6,8 @@
|
|
6
6
|
[![Code Climate Coverage](https://codeclimate.com/github/artirix/artirix_cache_service/coverage.png)](https://codeclimate.com/github/artirix/artirix_cache_service)
|
7
7
|
|
8
8
|
The basic use of this gem is to compile a cache key based on a given key prefix
|
9
|
-
and some extra variables or
|
10
|
-
|
11
|
-
TODO: also help with the cache options.
|
9
|
+
and some extra variables or arguments, with some helper methods. It also helps
|
10
|
+
with the cache options.
|
12
11
|
|
13
12
|
## Usage: `.key`
|
14
13
|
|
@@ -82,6 +81,27 @@ ArtirixCacheService.key :some_key, :arg1, 'arg2', digest: [arg3, arg4]
|
|
82
81
|
# => "prfx/some_key/arg1/arg2/7448a071aeee91fc9ee1c705f15445fdd8411224"
|
83
82
|
```
|
84
83
|
|
84
|
+
### `request` as special digest part
|
85
|
+
|
86
|
+
we can pass the request as a special argument. The Service will invoke `fullpath`
|
87
|
+
on it in the final digest.
|
88
|
+
|
89
|
+
It uses a parameterized version of the fullpath followed by a untouched version,
|
90
|
+
to avoid any collision.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
request
|
94
|
+
# => an ActionDispatch::Request, or any object that responds to `fullpath`
|
95
|
+
|
96
|
+
request.fullpath # => "/some/path?with=arguments"
|
97
|
+
|
98
|
+
ArtirixCacheService.key :some_key, :arg1, 'arg2', request: request
|
99
|
+
# => "prfx/some_key/arg1/arg2/1d3c96f449b8d21df75ebcf378c8f2455bf4e93c"
|
100
|
+
|
101
|
+
# >> Digest::SHA1.hexdigest [request.fullpath.parameterize, request.fullpath].to_s
|
102
|
+
# => "1d3c96f449b8d21df75ebcf378c8f2455bf4e93c"
|
103
|
+
```
|
104
|
+
|
85
105
|
## Usage: `.options`
|
86
106
|
|
87
107
|
used for getting the cache options based on the registered defaults and the registered options.
|
@@ -257,6 +277,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/artiri
|
|
257
277
|
|
258
278
|
# Changeset
|
259
279
|
|
280
|
+
## v0.3.1
|
281
|
+
|
282
|
+
- add request support
|
283
|
+
|
260
284
|
## v0.3.0
|
261
285
|
|
262
286
|
- add Redis support
|
@@ -40,18 +40,32 @@ module ArtirixCacheService
|
|
40
40
|
def cache_key_from_options(hash)
|
41
41
|
return nil unless hash.kind_of? Hash
|
42
42
|
|
43
|
-
|
44
|
-
v = variables_hash(Array(hash[:variables])).presence
|
43
|
+
parts = digest_hash_parts(hash).map(&:presence).compact
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
case parts.size
|
46
|
+
when 0
|
47
|
+
nil
|
48
|
+
when 1
|
49
|
+
digest parts.first
|
50
50
|
else
|
51
|
-
digest
|
51
|
+
digest parts
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
def digest_hash_parts(hash)
|
56
|
+
[
|
57
|
+
hash[:digest],
|
58
|
+
variables_hash(Array(hash[:variables])),
|
59
|
+
request_list(hash[:request]),
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
63
|
+
def request_list(request)
|
64
|
+
return nil unless request.present? && request.fullpath.present?
|
65
|
+
|
66
|
+
[request.fullpath.parameterize, request.fullpath]
|
67
|
+
end
|
68
|
+
|
55
69
|
def variables_hash(variable_names)
|
56
70
|
Hash[variable_names.map { |var| [var, variable_get(var)] }]
|
57
71
|
end
|