async_cache 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52981fb455f8efb0f4995d5f14062b3fa0a5ff9e
4
- data.tar.gz: 9c0a23d586fdb1fed9741112a1a2f226ce72aa40
3
+ metadata.gz: d672798f9a1aac8ba14134c46379e28dd0eb1de4
4
+ data.tar.gz: c590ed218b9717d22a02e5e4583f8210e38ea9ed
5
5
  SHA512:
6
- metadata.gz: 37a1491c788a2e71b575b8c3124b52089c394090daed0838787d8c83d885c5c140d0769ba2b54349198c0a87d0e8dabd2b8fa847af392262f8e6b8b48e9ab625
7
- data.tar.gz: c0c13544a791f15c1a942aa91d88b88099d8748b6de1b0519342b795ca6f634335aefdd76bfbe3cb2f14ae5bcef168a91c7782ee65633cfe0dc00d3eb3b53df1
6
+ metadata.gz: aaf71d240d334648fc1816fa060ca35eb9b497fc02e03b81c59666f22668feb6dbfdcb680263e2ad4a41fda4ed0d8933612e3a946d7756cb1443753158f228e8
7
+ data.tar.gz: 28bb134215e14a0fe25723ab0ecee482db0eb5147bcdc301e8e3e63356daaa854710f00ade60a08c0c244d206bd3a1e22ac6c98cc155c3c16de8c2dc2260e2aa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- async_cache (0.0.1)
4
+ async_cache (0.0.2)
5
5
  sourcify (~> 0.5.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -33,6 +33,8 @@ async_cache.fetch(key, version, arguments: [id]) do |id|
33
33
  end
34
34
  ```
35
35
 
36
+ For additional examples see the [`examples`](examples/) folder.
37
+
36
38
  ## Strategy
37
39
 
38
40
  Async-cache follows a straightforward strategy for determining which action to take when a cache entry is fetched:
@@ -0,0 +1,42 @@
1
+ # This is an example of how to use AsyncCache in a Rails API controller; it
2
+ # is loosely based on patterns currently in use in production at Everlane.
3
+
4
+ class ExamplesController < ApplicationController
5
+ def index
6
+ locator = 'examples'
7
+ version = Example.maximum :updated_at
8
+ options = {
9
+ expires_in: 1.week,
10
+ # Force it to synchronously regenerate for admin users so that they
11
+ # can see their changes reflected immediately
12
+ synchronous_regen: current_user.admin?
13
+ }
14
+
15
+ json = async_cache.fetch(locator, version, options) do
16
+ ExamplesPresenter.new.to_json
17
+ end
18
+
19
+ self.response_body = json
20
+ self.content_type = 'application/json'
21
+ end
22
+
23
+ private
24
+
25
+ def async_cache
26
+ Rails.application.config.async_cache
27
+ end
28
+ end
29
+
30
+ # We use presenters at Everlane as a sort of view-model. Controllers handle
31
+ # application logic such as writing to the database or redirecting clients
32
+ # while presenters handle loading data for the views and rendering views.
33
+
34
+ class ExamplesPresenter < Presenter
35
+ def initialize
36
+ @examples = Example.all
37
+ end
38
+
39
+ def to_json
40
+ @examples.map(&:as_json).to_json
41
+ end
42
+ end
@@ -77,9 +77,11 @@ module AsyncCache
77
77
  end
78
78
 
79
79
  def generate_and_cache(key:, version:, expires_in:, block:, arguments:)
80
+ block_source = block.to_source
81
+
80
82
  # Mimic the destruction-of-scope behavior of the worker in development
81
83
  # so it will *fail* for developers if they try to depend upon scope
82
- block = eval(block.to_source)
84
+ block = eval(block_source)
83
85
 
84
86
  data = block.call(*arguments)
85
87
 
@@ -1,3 +1,3 @@
1
1
  module AsyncCache
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Derewecki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-15 00:00:00.000000000 Z
12
+ date: 2015-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sourcify
@@ -67,6 +67,7 @@ files:
67
67
  - LICENSE
68
68
  - README.md
69
69
  - async_cache.gemspec
70
+ - examples/examples_controller.rb
70
71
  - lib/async_cache.rb
71
72
  - lib/async_cache/store.rb
72
73
  - lib/async_cache/version.rb