redisize 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -6
- data/lib/redisize/version.rb +1 -1
- data/lib/redisize.rb +4 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 354b2f1ac302400888ebd67b99b59177d615c685273b21ae4feb4ab3b1c6582f
|
4
|
+
data.tar.gz: 9475c6209ffb1c840bc1da7754dd996e100796e2d37979da9eeee479e97d311e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 692729405db96ff8132a4ec0d2eb9bd655000cf5ccb1d39d791c66c2f258f92f2b2f2ae885c8716b5fdebdc322af6478b76119e47f9e2c3c69f09dd0b81678eb
|
7
|
+
data.tar.gz: 17fc2e30bc58f236675a439424c3c7b17a894861febd7595a6d267c9a7c7520cce877ae67a8f94d3ff6c4d8201bdaf3d5cd7d2f480c111787436f88b8c14ae60
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Redisize
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
The gem allows to use asynchonous way to cache or just store in redis or any other cache mechanism. For asynchronous caching the Resque or Sidekiq adapters can be used, for synchronous - inline.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,54 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
### Initialization
|
24
|
+
Usually adapter can'be defined automatically of presently installed gems. Curretly are supported sidekiq and resque gems to ansyncronous caching (redisizing). If no such gems are installed, the synchronous **inline** adapter is used. You can redefine manually an adapter as follows:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Redisize.adapter_kind = :inline
|
28
|
+
```
|
29
|
+
|
30
|
+
Other values are ```:resque```, and ```:sidekiq```.
|
31
|
+
And then to use the gem just define in the target object:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
include(Redisize)
|
35
|
+
```
|
36
|
+
|
37
|
+
### In Rails
|
38
|
+
|
39
|
+
To use the cache feature with Rails (and ActiveRecord) you have just to wrap a method accessing DB either a record or a relation to a block like this. So to redisize a record value as a json use the follwing:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
redisize_json(attrs) do
|
43
|
+
# <JSON generation code>
|
44
|
+
# generate_json(attrs, options)
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
to drop a JSON value use:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
deredisize_json(attrs)
|
52
|
+
```
|
53
|
+
|
54
|
+
to redisize an SQL:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
redisize_sql do
|
58
|
+
relation.as_json(context)
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
to redisize an record instance use:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
redisize_model(slug, by_key: :slug) do
|
66
|
+
self.joins(:slug).where(slugs: {text: slug}).first
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
Next calls to the block will return a cached value. Updating the record will drop cache for sql or record itself.
|
26
71
|
|
27
72
|
## Development
|
28
73
|
|
@@ -32,7 +77,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
77
|
|
33
78
|
## Contributing
|
34
79
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/majioa/redisize. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/majioa/redisize/blob/master/CODE_OF_CONDUCT.md).
|
36
81
|
|
37
82
|
|
38
83
|
## License
|
@@ -41,4 +86,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
86
|
|
42
87
|
## Code of Conduct
|
43
88
|
|
44
|
-
Everyone interacting in the Redisize project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
89
|
+
Everyone interacting in the Redisize project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/majioa/redisize/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/redisize/version.rb
CHANGED
data/lib/redisize.rb
CHANGED
@@ -175,10 +175,6 @@ module Redisize
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
def as_json_for instance
|
179
|
-
instance.attribute_names.map {|x|[x, instance.read_attribute(x)] }.to_h
|
180
|
-
end
|
181
|
-
|
182
178
|
### internal methods for enqueued proceeds
|
183
179
|
#
|
184
180
|
def redisize_model_metas metakey, model_name, attrs, key
|
@@ -272,7 +268,7 @@ module Redisize
|
|
272
268
|
|
273
269
|
# self -> model instance
|
274
270
|
def reredisize_instance
|
275
|
-
attrs =
|
271
|
+
attrs = self.as_json
|
276
272
|
key = Redisize.key_name_for(self.class.polymorphic_base_name, attrs, "instance")
|
277
273
|
|
278
274
|
# binding.pry
|
@@ -282,7 +278,7 @@ module Redisize
|
|
282
278
|
|
283
279
|
# self -> model instance
|
284
280
|
def deredisize_instance
|
285
|
-
attrs =
|
281
|
+
attrs = self.as_json
|
286
282
|
key = Redisize.key_name_for(self.class.polymorphic_base_name, attrs, "instance")
|
287
283
|
|
288
284
|
# binding.pry
|
@@ -318,12 +314,12 @@ module Redisize
|
|
318
314
|
def redisize_model value, options = {}, &block
|
319
315
|
primary_key = options.fetch(:by_key, self.primary_key).to_s
|
320
316
|
key = ["instance", name, primary_key, value]
|
321
|
-
metakey = ["meta", self.
|
317
|
+
metakey = ["meta", self.polymorphic_base_name, primary_key, value]
|
322
318
|
|
323
319
|
# binding.pry
|
324
320
|
redisize_cache_fetch(key, expires_in: 1.week) do
|
325
321
|
if result = block.call
|
326
|
-
Redisize.enqueue(:redisize_model_metas, metakey, self.name,
|
322
|
+
Redisize.enqueue(:redisize_model_metas, metakey, self.name, result.as_json, key)
|
327
323
|
end
|
328
324
|
|
329
325
|
result
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redisize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel «Malo» Skrylev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.3.26
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Make json record cacheable to redis
|