async-http-cache 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2439c0fb975f956215ef9eec1e8db38394e10608a4299253516fee12540b5e6f
4
- data.tar.gz: 616e0a00b3e6fa00c85c29cede66c464b887ca8d56188e93b84cf6ec5d19f7a4
3
+ metadata.gz: dc8d7b58e3ba4a009b05a55f06a7ffbc546b20aa9d916c3b4bbaf054a99a9f38
4
+ data.tar.gz: d6b71693a4f9272862f9e710b295a56966047411fcb903ef4029b30c2605b5a9
5
5
  SHA512:
6
- metadata.gz: aadf8138fab28ffedeaa0a74f4dedf6f888d84394e4668e6d42757bf8c87e6bad50c9afbd7477d2a26e84294c4ce13db964f4a5567badd7a994434440c0e7a73
7
- data.tar.gz: 976634254e072fe0ea9f950da879d75954b2b5b56f3de52b9e4d42c10a19b71ed840ddd3c61660f5fa9efaa39ed06fbc5ac24585ebe21615f8ff4d542fff7d93
6
+ metadata.gz: 19269b3b4e941221415d4b94f9aa022ac49df8ed3f3e6b96a08f3eb48e6e224f3e68b16c56892fd69c0f4956eb6b79882abc515547a031207ab92d1b2be79c09
7
+ data.tar.gz: 20a5a417aff84525e438667966dda756e57db643fe4ab236461c934d6c7ae4d6b92d53e273f720bcb62a85b70562e24e1623c4c0dbcb97fd20b0ecf3f5d01dd3
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- .,-�t�Q����V <#>Ai,��i��J@���ك�l f�>b�"U�*�), v��%Ou���k_�\��:�����
2
- �=���ղ`+��7)��l�Q��:�Zx���
1
+ t���̻�[������4���oO
2
+ 2W��CC�f$�����`�ŃB�Gp�{P W&X;Z� >!�Fa��H�.
3
+ `
@@ -1,29 +1,15 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
22
5
 
23
6
  require 'protocol/http/body/rewindable'
24
7
  require 'protocol/http/body/completable'
25
8
  require 'protocol/http/body/digestable'
26
9
 
10
+ require 'console'
11
+ require 'console/event/failure'
12
+
27
13
  module Async
28
14
  module HTTP
29
15
  module Cache
@@ -53,7 +39,7 @@ module Async
53
39
  # Wrap the response with the callback:
54
40
  ::Protocol::HTTP::Body::Completable.wrap(response) do |error|
55
41
  if error
56
- Console.logger.error(self) {error}
42
+ Console::Event::Failure.for(error).emit(self)
57
43
  else
58
44
  yield response, rewindable.buffered
59
45
  end
@@ -1,24 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
5
+ # Copyright, 2022, by Colin Kelley.
22
6
 
23
7
  require 'set'
24
8
  require 'protocol/http/middleware'
@@ -30,13 +14,15 @@ require_relative 'store'
30
14
  module Async
31
15
  module HTTP
32
16
  module Cache
17
+ # Implements a general shared cache according to https://www.rfc-editor.org/rfc/rfc9111
33
18
  class General < ::Protocol::HTTP::Middleware
34
19
  CACHE_CONTROL = 'cache-control'
35
-
20
+
36
21
  CONTENT_TYPE = 'content-type'
37
22
  AUTHORIZATION = 'authorization'
38
23
  COOKIE = 'cookie'
39
-
24
+ SET_COOKIE = 'set-cookie'
25
+
40
26
  # Status codes of responses that MAY be stored by a cache or used in reply
41
27
  # to a subsequent request.
42
28
  #
@@ -50,69 +36,104 @@ module Async
50
36
  404 => true, # Not Found
51
37
  410 => true # Gone
52
38
  }.freeze
53
-
39
+
54
40
  def initialize(app, store: Store.default)
55
41
  super(app)
56
-
42
+
57
43
  @count = 0
58
-
44
+
59
45
  @store = store
60
46
  end
61
-
47
+
62
48
  attr :count
63
49
  attr :store
64
-
50
+
65
51
  def close
66
52
  @store.close
67
53
  ensure
68
54
  super
69
55
  end
70
-
56
+
71
57
  def key(request)
72
58
  @store.normalize(request)
73
-
59
+
74
60
  [request.authority, request.method, request.path]
75
61
  end
76
-
77
- def cacheable?(request)
62
+
63
+ def cacheable_request?(request)
78
64
  # We don't support caching requests which have a request body:
79
65
  if request.body
80
66
  return false
81
67
  end
82
-
68
+
83
69
  # We can't cache upgraded requests:
84
70
  if request.protocol
85
71
  return false
86
72
  end
87
-
73
+
88
74
  # We only support caching GET and HEAD requests:
89
75
  unless request.method == 'GET' || request.method == 'HEAD'
90
76
  return false
91
77
  end
92
-
78
+
93
79
  if request.headers[AUTHORIZATION]
94
80
  return false
95
81
  end
96
-
82
+
97
83
  if request.headers[COOKIE]
98
84
  return false
99
85
  end
100
-
86
+
101
87
  # Otherwise, we can cache it:
102
88
  return true
103
89
  end
104
-
105
- def wrap(key, request, response)
90
+
91
+ def cacheable_response_headers?(headers)
92
+ if cache_control = headers[CACHE_CONTROL]
93
+ if cache_control.no_store? || cache_control.private?
94
+ Console.logger.debug(self, cache_control: cache_control) {"Cannot cache response with cache-control header!"}
95
+ return false
96
+ end
97
+ end
98
+
99
+ if set_cookie = headers[SET_COOKIE]
100
+ Console.logger.debug(self) {"Cannot cache response with set-cookie header!"}
101
+ return false
102
+ end
103
+
104
+ return true
105
+ end
106
+
107
+ def cacheable_response?(response)
108
+ # At this point, we know response.status and response.headers.
109
+ # But we don't know response.body or response.headers.trailer.
106
110
  unless CACHEABLE_RESPONSE_CODES.include?(response.status)
107
- return response
111
+ Console.logger.debug(self, status: response.status) {"Cannot cache response with status code!"}
112
+ return false
108
113
  end
109
114
 
110
- response_cache_control = response.headers[CACHE_CONTROL]
111
-
112
- if response_cache_control&.no_store? || response_cache_control&.private?
113
- return response
115
+ unless cacheable_response_headers?(response.headers)
116
+ Console.logger.debug(self) {"Cannot cache response with uncacheable headers!"}
117
+ return false
114
118
  end
115
-
119
+
120
+ return true
121
+ end
122
+
123
+ # Semantically speaking, it is possible for trailers to result in an uncacheable response, so we need to check for that.
124
+ def proceed_with_response_cache?(response)
125
+ if response.headers.trailer?
126
+ unless cacheable_response_headers?(response.headers)
127
+ Console.logger.debug(self, trailer: trailer.keys) {"Cannot cache response with trailer header!"}
128
+ return false
129
+ end
130
+ end
131
+
132
+ return true
133
+ end
134
+
135
+ # Potentially wrap the response so that it updates the cache, if caching is possible.
136
+ def wrap(key, request, response)
116
137
  if request.head? and body = response.body
117
138
  unless body.empty?
118
139
  Console.logger.warn(self) {"HEAD request resulted in non-empty body!"}
@@ -120,34 +141,46 @@ module Async
120
141
  return response
121
142
  end
122
143
  end
123
-
144
+
145
+ unless cacheable_request?(request)
146
+ Console.logger.debug(self) {"Cannot cache request!"}
147
+ return response
148
+ end
149
+
150
+ unless cacheable_response?(response)
151
+ Console.logger.debug(self) {"Cannot cache response!"}
152
+ return response
153
+ end
154
+
124
155
  return Body.wrap(response) do |response, body|
125
- Console.logger.debug(self) {"Updating cache for #{key}..."}
126
- @store.insert(key, request, Response.new(response, body))
156
+ if proceed_with_response_cache?(response)
157
+ key ||= self.key(request)
158
+
159
+ Console.logger.debug(self, key: key) {"Updating miss!"}
160
+ @store.insert(key, request, Response.new(response, body))
161
+ end
127
162
  end
128
163
  end
129
164
 
130
165
  def call(request)
131
- key = self.key(request)
132
-
133
166
  cache_control = request.headers[CACHE_CONTROL]
134
-
167
+
135
168
  unless cache_control&.no_cache?
169
+ key = self.key(request)
170
+
136
171
  if response = @store.lookup(key, request)
137
- Console.logger.debug(self) {"Cache hit for #{key}..."}
172
+ Console.logger.debug(self, key: key) {"Cache hit!"}
138
173
  @count += 1
139
-
174
+
140
175
  # Return the cached response:
141
176
  return response
142
177
  end
143
178
  end
144
-
179
+
145
180
  unless cache_control&.no_store?
146
- if cacheable?(request)
147
- return wrap(key, request, super)
148
- end
181
+ return wrap(key, request, super)
149
182
  end
150
-
183
+
151
184
  return super
152
185
  end
153
186
  end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
22
5
 
23
6
  require 'protocol/http/response'
24
7
  require 'async/clock'
@@ -28,7 +11,6 @@ module Async
28
11
  module Cache
29
12
  class Response < ::Protocol::HTTP::Response
30
13
  CACHE_CONTROL = 'cache-control'
31
- SET_COOKIE = 'set-cookie'
32
14
  ETAG = 'etag'
33
15
 
34
16
  X_CACHE = 'x-cache'
@@ -56,24 +38,6 @@ module Async
56
38
  @etag ||= @headers[ETAG]
57
39
  end
58
40
 
59
- def cacheable?
60
- if cache_control = @headers[CACHE_CONTROL]
61
- if cache_control.private? || !cache_control.public?
62
- return false
63
- end
64
- else
65
- # No cache control header...
66
- return false
67
- end
68
-
69
- if set_cookie = @headers[SET_COOKIE]
70
- Console.logger.warn(self) {"Cannot cache response with set-cookie header!"}
71
- return false
72
- end
73
-
74
- return true
75
- end
76
-
77
41
  def age
78
42
  Async::Clock.now - @generated_at
79
43
  end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
22
5
 
23
6
  module Async
24
7
  module HTTP
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
22
5
 
23
6
  module Async
24
7
  module HTTP
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
22
5
 
23
6
  require_relative 'store/memory'
24
7
  require_relative 'store/vary'
@@ -1,29 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
22
5
 
23
6
  module Async
24
7
  module HTTP
25
8
  module Cache
26
- VERSION = "0.4.3"
9
+ VERSION = "0.4.4"
27
10
  end
28
11
  end
29
12
  end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
22
5
 
23
6
  require_relative "cache/version"
24
7
  require_relative "cache/general"
data/license.md ADDED
@@ -0,0 +1,23 @@
1
+ # MIT License
2
+
3
+ Copyright, 2020-2024, by Samuel Williams.
4
+ Copyright, 2021, by Olle Jonsson.
5
+ Copyright, 2022, by Colin Kelley.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,53 @@
1
+ # Async::HTTP::Cache
2
+
3
+ Provides a cache middleware for `Async::HTTP` clients and servers.
4
+
5
+ [![Development Status](https://github.com/socketry/async-http-cache/workflows/Test/badge.svg)](https://github.com/socketry/async-http-cache/actions?workflow=Test)
6
+
7
+ ## Usage
8
+
9
+ ### Client Side
10
+
11
+ ``` ruby
12
+ require 'async'
13
+ require 'async/http'
14
+ require 'async/http/cache'
15
+
16
+ endpoint = Async::HTTP::Endpoint.parse("https://www.oriontransfer.co.nz")
17
+ client = Async::HTTP::Client.new(endpoint)
18
+ cache = Async::HTTP::Cache::General.new(client)
19
+
20
+ Async do
21
+ 2.times do
22
+ response = cache.get("/products/index")
23
+ puts response.inspect
24
+ # <Async::HTTP::Protocol::HTTP2::Response ...>
25
+ # <Async::HTTP::Cache::Response ...>
26
+ response.finish
27
+ end
28
+ ensure
29
+ cache.close
30
+ end
31
+ ```
32
+
33
+ ## Vary
34
+
35
+ The `vary` header creates a headache for proxy implementations, because it creates a combinatorial explosion of cache keys, even if the content is the same. Try to avoid it unless absolutely necessary.
36
+
37
+ ## Contributing
38
+
39
+ We welcome contributions to this project.
40
+
41
+ 1. Fork it.
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
44
+ 4. Push to the branch (`git push origin my-new-feature`).
45
+ 5. Create new Pull Request.
46
+
47
+ ### Developer Certificate of Origin
48
+
49
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
50
+
51
+ ### Community Guidelines
52
+
53
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-http-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Colin Kelley
8
9
  - Olle Jonsson
9
10
  autorequire:
10
11
  bindir: bin
@@ -38,7 +39,7 @@ cert_chain:
38
39
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
40
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
41
  -----END CERTIFICATE-----
41
- date: 2022-08-23 00:00:00.000000000 Z
42
+ date: 2024-07-18 00:00:00.000000000 Z
42
43
  dependencies:
43
44
  - !ruby/object:Gem::Dependency
44
45
  name: async-http
@@ -54,48 +55,6 @@ dependencies:
54
55
  - - "~>"
55
56
  - !ruby/object:Gem::Version
56
57
  version: '0.56'
57
- - !ruby/object:Gem::Dependency
58
- name: async-rspec
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '1.10'
64
- type: :development
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: '1.10'
71
- - !ruby/object:Gem::Dependency
72
- name: covered
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- type: :development
79
- prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: '0'
85
- - !ruby/object:Gem::Dependency
86
- name: rspec
87
- requirement: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: '0'
92
- type: :development
93
- prerelease: false
94
- version_requirements: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
58
  description:
100
59
  email:
101
60
  executables: []
@@ -110,10 +69,13 @@ files:
110
69
  - lib/async/http/cache/store/memory.rb
111
70
  - lib/async/http/cache/store/vary.rb
112
71
  - lib/async/http/cache/version.rb
72
+ - license.md
73
+ - readme.md
113
74
  homepage: https://github.com/socketry/async-http-cache
114
75
  licenses:
115
76
  - MIT
116
- metadata: {}
77
+ metadata:
78
+ source_code_uri: https://github.com/socketry/async-http-cache.git
117
79
  post_install_message:
118
80
  rdoc_options: []
119
81
  require_paths:
@@ -122,14 +84,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
84
  requirements:
123
85
  - - ">="
124
86
  - !ruby/object:Gem::Version
125
- version: 2.3.0
87
+ version: '3.1'
126
88
  required_rubygems_version: !ruby/object:Gem::Requirement
127
89
  requirements:
128
90
  - - ">="
129
91
  - !ruby/object:Gem::Version
130
92
  version: '0'
131
93
  requirements: []
132
- rubygems_version: 3.3.7
94
+ rubygems_version: 3.5.11
133
95
  signing_key:
134
96
  specification_version: 4
135
97
  summary: Standard-compliant cache for async-http.
metadata.gz.sig CHANGED
Binary file