async_cache 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +18 -11
- data/Rakefile +4 -0
- data/lib/async_cache/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ebb087efa77e51ac632b1fdb6e5bc646c8fc924
|
4
|
+
data.tar.gz: 87c132d6f30e941a877bf2c5b221a2ab657e7aa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3249570fd6634cca700cb69a4de34c2f4a9966df8db958ac4d701da432ae8b51e81730fd26b91d5a8e2e557bcf3d8c5a47f5bba815617675564dee07cdfcc506
|
7
|
+
data.tar.gz: 1b00cf6f828c2d61497979df32cff4e4f76853e9bb13b2765a6dbb84dcecdd9c267394a8888950790a5a505007b9de64452974a5fcac6332ab9d40f92b6168de
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -15,25 +15,32 @@ gem 'async_cache'
|
|
15
15
|
Then set up a store and fetch from it:
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
#
|
19
|
-
|
20
|
-
# deduplication features).
|
21
|
-
async_cache = AsyncCache::Store.new(
|
18
|
+
# (in config/initializers/async_cache.rb)
|
19
|
+
ASYNC_CACHE = AsyncCache::Store.new(
|
22
20
|
backend: Rails.cache,
|
23
21
|
worker: :active_job
|
24
22
|
)
|
25
23
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
# (in app/controllers/things_controller.rb)
|
25
|
+
def show
|
26
|
+
# Then use it to do some heavy lifting asychronously
|
27
|
+
id = params[:id]
|
28
|
+
key = "thing/#{id}"
|
29
|
+
version = Thing.select(:updated_at).find(id).updated_at
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
json = ASYNC_CACHE.fetch(key, version, arguments: [id]) do |id|
|
32
|
+
Thing.find(id).to_json
|
33
|
+
end
|
34
|
+
|
35
|
+
render body: json, content_type: 'application/json'
|
33
36
|
end
|
34
37
|
```
|
35
38
|
|
36
|
-
For additional examples see the [`examples`](examples/)
|
39
|
+
For additional examples see the [`examples`](examples/) directory.
|
40
|
+
|
41
|
+
#### Workers
|
42
|
+
|
43
|
+
Async-cache provides a generic [ActiveJob](https://github.com/rails/rails/tree/master/activejob) worker as well as a specialized [Sidekiq](https://github.com/mperham/sidekiq) worker (see the [`workers`](lib/async_cache/workers/) directory). The ActiveJob worker should work out of the box is most cases. The Sidekiq worker provides special deduplication functionality which should significantly reduce the queue size/worker process load for high-traffic sites.
|
37
44
|
|
38
45
|
## Strategy
|
39
46
|
|
data/Rakefile
ADDED
data/lib/async_cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Derewecki
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- Gemfile.lock
|
67
67
|
- LICENSE
|
68
68
|
- README.md
|
69
|
+
- Rakefile
|
69
70
|
- async_cache.gemspec
|
70
71
|
- examples/examples_controller.rb
|
71
72
|
- lib/async_cache.rb
|