lhs 13.0.0 → 13.0.1
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 +4 -4
- data/README.md +11 -5
- data/lib/lhs/concerns/record/request_cycle_cache/interceptor.rb +7 -5
- data/lib/lhs/config.rb +4 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/request_cycle_cache/main_spec.rb +13 -0
- data/spec/support/request_cycle_cache.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 163b82a58eaed908884ea40ab28605f01323a4bd
|
4
|
+
data.tar.gz: 66320f0e30fcecc454702e089a4a3f2630cd6dce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bb2c9f3b2725aaa43724025054e2ed1a53e21c62c8c2fb5ed26bbd2e9fedf399a20c1d5d3d422fa6ea35602fddb1a19e39fc3336d18388f9a755a5fa1bd9cb5
|
7
|
+
data.tar.gz: 4a90025e71d0ee499cde8ee06faf08363ad15aea0c2eea44e1d7de7c1b72331f00bc34a5184ab1eb0c5e378c9460d24c9af2bf9c4c9707d58fdbb269497601bf
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ gem 'lhs'
|
|
12
12
|
LHS comes with Request Cycle Cache – enabled by default. It requires [LHC Caching Interceptor](https://github.com/local-ch/lhc/blob/master/docs/interceptors/caching.md) to be enabled:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
# intializers/lhc.rb
|
15
|
+
# intializers/lhc.rb
|
16
16
|
LHC.configure do |config|
|
17
17
|
config.interceptors = [LHC::Caching]
|
18
18
|
end
|
@@ -285,7 +285,7 @@ You can apply options to the request chain. Those options will be forwarded to t
|
|
285
285
|
|
286
286
|
## Request Cycle Cache
|
287
287
|
|
288
|
-
By default, LHS does not perform the same http request during one request cycle multiple times.
|
288
|
+
By default, LHS does not perform the same http request during one request cycle multiple times.
|
289
289
|
|
290
290
|
It uses the [LHC Caching Interceptor](https://github.com/local-ch/lhc/blob/master/docs/interceptors/caching.md) as caching mechanism base and sets a unique request id for every request cycle with Railties to ensure data is just cached within one request cycle and not shared with other requests.
|
291
291
|
|
@@ -299,6 +299,12 @@ If you want to disable the LHS Request Cycle Cache, simply disable it within con
|
|
299
299
|
LHS.config.request_cycle_cache_enabled = false
|
300
300
|
```
|
301
301
|
|
302
|
+
By default the LHS Request Cycle Cache will use `ActiveSupport::Cache::MemoryStore` as its cache store. Feel free to configure a cache that is better suited for your needs by:
|
303
|
+
|
304
|
+
```ruby
|
305
|
+
LHS.config.request_cycle_cache = ActiveSupport::Cache::MemoryStore.new
|
306
|
+
```
|
307
|
+
|
302
308
|
## Batch processing
|
303
309
|
|
304
310
|
**Be careful using methods for batch processing. They could result in a lot of HTTP requests!**
|
@@ -683,7 +689,7 @@ record.update(recommended: false)
|
|
683
689
|
Based on [ActiveRecord's implementation](http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-becomes), LHS implements `becomes`, too.
|
684
690
|
It's a way to convert records of a certain type A to another certain type B.
|
685
691
|
|
686
|
-
_NOTE: RPC-style actions, that are discouraged in REST anyway, are utilizable with this functionality, too. See the following example:_
|
692
|
+
_NOTE: RPC-style actions, that are discouraged in REST anyway, are utilizable with this functionality, too. See the following example:_
|
687
693
|
|
688
694
|
```ruby
|
689
695
|
class Location < LHS::Record
|
@@ -792,9 +798,9 @@ end
|
|
792
798
|
|
793
799
|
# view.html
|
794
800
|
= form_for @customer, as: :customer do |customer_form|
|
795
|
-
|
801
|
+
|
796
802
|
= fields_for 'customer[:address]', @customer.address, do |address_form|
|
797
|
-
|
803
|
+
|
798
804
|
= fields_for 'customer[:address][:street]', @customer.address.street, do |street_form|
|
799
805
|
|
800
806
|
= street_form.input :name
|
@@ -12,11 +12,13 @@ class LHS::Record
|
|
12
12
|
|
13
13
|
def before_request(request)
|
14
14
|
request.options = request.options.merge({
|
15
|
-
cache:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
cache: {
|
16
|
+
expires_in: 5.minutes,
|
17
|
+
race_condition_ttl: 5.seconds,
|
18
|
+
key: cache_key_for(request),
|
19
|
+
methods: CACHED_METHODS,
|
20
|
+
use: LHS.config.request_cycle_cache
|
21
|
+
}
|
20
22
|
}.merge(request.options))
|
21
23
|
end
|
22
24
|
|
data/lib/lhs/config.rb
CHANGED
@@ -3,9 +3,12 @@ require 'singleton'
|
|
3
3
|
class LHS::Config
|
4
4
|
include Singleton
|
5
5
|
|
6
|
-
attr_accessor :request_cycle_cache_enabled
|
6
|
+
attr_accessor :request_cycle_cache_enabled, :request_cycle_cache
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
self.request_cycle_cache_enabled ||= true
|
10
|
+
if defined?(ActiveSupport::Cache::MemoryStore)
|
11
|
+
self.request_cycle_cache ||= ActiveSupport::Cache::MemoryStore.new
|
12
|
+
end
|
10
13
|
end
|
11
14
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -87,4 +87,17 @@ describe 'Request Cycle Cache', type: :request do
|
|
87
87
|
expect(request).to have_been_made.times(2)
|
88
88
|
end
|
89
89
|
end
|
90
|
+
|
91
|
+
context 'use: cache' do
|
92
|
+
let!(:old_cache) { LHS.config.request_cycle_cache }
|
93
|
+
before { LHS.config.request_cycle_cache = double('cache', fetch: nil, write: nil) }
|
94
|
+
after { LHS.config.request_cycle_cache = old_cache }
|
95
|
+
|
96
|
+
it 'uses the cache passed in',
|
97
|
+
cleanup_before: true, request_cycle_cache: true do
|
98
|
+
expect(LHS.config.request_cycle_cache).to receive(:fetch).at_least(:once)
|
99
|
+
expect(LHS.config.request_cycle_cache).to receive(:write).at_least(:once)
|
100
|
+
get '/request_cycle_cache/simple'
|
101
|
+
end
|
102
|
+
end
|
90
103
|
end
|
@@ -3,5 +3,6 @@ RSpec.configure do |config|
|
|
3
3
|
enabled = spec.metadata.key?(:request_cycle_cache) && spec.metadata[:request_cycle_cache] == true
|
4
4
|
enabled ||= false
|
5
5
|
LHS.config.request_cycle_cache_enabled = enabled
|
6
|
+
LHS.config.request_cycle_cache = ActiveSupport::Cache::MemoryStore.new
|
6
7
|
end
|
7
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 13.0.
|
4
|
+
version: 13.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -414,7 +414,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
414
414
|
requirements:
|
415
415
|
- Ruby >= 2.3.0
|
416
416
|
rubyforge_project:
|
417
|
-
rubygems_version: 2.6.
|
417
|
+
rubygems_version: 2.6.12
|
418
418
|
signing_key:
|
419
419
|
specification_version: 4
|
420
420
|
summary: Rails gem providing an easy, active-record-like interface for http json services
|