lhc-core-interceptors 2.3.3 → 2.4.0
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 +18 -0
- data/lib/lhc-core-interceptors.rb +8 -1
- data/lib/lhc-core-interceptors/caching.rb +8 -3
- data/lib/lhc-core-interceptors/railtie.rb +8 -0
- data/lib/lhc-core-interceptors/test/cache_helper.rb +7 -0
- data/lib/lhc-core-interceptors/version.rb +1 -1
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06055f3a1962c8675da6aa73da1256fbe733e02f
|
4
|
+
data.tar.gz: c504a736602334e94a6f5ddbc6d55e5eee46fc13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b81ad3581b2a80274c96f12b39be97132a38e3ac1ccb0d7bc2c1d85efa51a9bc0e332d6f0226b7cc233267abe26680eee195a0a56461cafdcee0ba800fbac94f
|
7
|
+
data.tar.gz: 9dc9f095a8a3560827fb25607e92e6d071bc5351bed5432d9c27ca1d1a38db3b788101fc0b13b83f0305103b2919380ec81a074000d4ad092746fbf2d6109b25
|
data/README.md
CHANGED
@@ -11,6 +11,14 @@ Add the cache interceptor to your basic set of LHC interceptors.
|
|
11
11
|
LHC.config.interceptors = [LHC::Caching]
|
12
12
|
```
|
13
13
|
|
14
|
+
You can configure your own cache (default Rails.cache) and logger (default Rails.logger):
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
LHC::Caching.cache = ActiveSupport::Cache::MemoryStore.new
|
18
|
+
LHC::Caching.logger = Logger.new(STDOUT)
|
19
|
+
```
|
20
|
+
|
21
|
+
|
14
22
|
Caching is not enabled by default, although you added it to your basic set of interceptors.
|
15
23
|
If you want to have requests served/stored and stored in/from cache, you have to enable it by request.
|
16
24
|
|
@@ -40,6 +48,16 @@ Setting `cache_race_condition_ttl` is very useful in situations where a cache en
|
|
40
48
|
If a cache expires and due to heavy load several different processes will try to read data natively and then they all will try to write to cache.
|
41
49
|
To avoid that case the first process to find an expired cache entry will bump the cache expiration time by the value set in `cache_race_condition_ttl`.
|
42
50
|
|
51
|
+
### Testing
|
52
|
+
|
53
|
+
Add to your spec_helper.rb:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require 'lhc-core-interceptors/test/cache_helper.rb'
|
57
|
+
```
|
58
|
+
|
59
|
+
This will initialize a MemoryStore cache for LHC::Caching interceptor and resets the cache before every test.
|
60
|
+
|
43
61
|
## Monitoring Interceptor
|
44
62
|
|
45
63
|
Add the monitoring interceptor to your basic set of LHC interceptors.
|
@@ -1,2 +1,9 @@
|
|
1
1
|
require 'lhc'
|
2
|
-
|
2
|
+
|
3
|
+
require 'lhc-core-interceptors/version'
|
4
|
+
require 'lhc-core-interceptors/auth'
|
5
|
+
require 'lhc-core-interceptors/caching'
|
6
|
+
require 'lhc-core-interceptors/monitoring'
|
7
|
+
require 'lhc-core-interceptors/rollbar'
|
8
|
+
|
9
|
+
require 'lhc-core-interceptors/railtie' if defined?(Rails)
|
@@ -1,4 +1,7 @@
|
|
1
1
|
class LHC::Caching < LHC::Interceptor
|
2
|
+
include ActiveSupport::Configurable
|
3
|
+
|
4
|
+
config_accessor :cache, :logger
|
2
5
|
|
3
6
|
CACHE_VERSION = '1'
|
4
7
|
|
@@ -9,17 +12,19 @@ class LHC::Caching < LHC::Interceptor
|
|
9
12
|
}
|
10
13
|
|
11
14
|
def before_request(request)
|
15
|
+
return unless cache
|
12
16
|
return unless request.options[:cache]
|
13
|
-
cached_response_data =
|
17
|
+
cached_response_data = cache.fetch(key(request))
|
14
18
|
return unless cached_response_data
|
15
|
-
|
19
|
+
logger.info "Served from cache: #{key(request)}" if logger
|
16
20
|
from_cache(request, cached_response_data)
|
17
21
|
end
|
18
22
|
|
19
23
|
def after_response(response)
|
24
|
+
return unless cache
|
20
25
|
request = response.request
|
21
26
|
return if !request.options[:cache] || !response.success?
|
22
|
-
|
27
|
+
cache.write(key(request), to_cache(response), options(request.options))
|
23
28
|
end
|
24
29
|
|
25
30
|
private
|
@@ -20,7 +20,7 @@ Rails.application.configure do
|
|
20
20
|
# config.action_dispatch.rack_cache = true
|
21
21
|
|
22
22
|
# Disable Rails's static asset server (Apache or nginx will already do this).
|
23
|
-
config.
|
23
|
+
config.serve_static_files = false
|
24
24
|
|
25
25
|
# Compress JavaScripts and CSS.
|
26
26
|
config.assets.js_compressor = :uglifier
|
@@ -13,7 +13,7 @@ Rails.application.configure do
|
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
15
|
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
-
config.
|
16
|
+
config.serve_static_files = true
|
17
17
|
config.static_cache_control = 'public, max-age=3600'
|
18
18
|
|
19
19
|
# Show full error reports and disable caching.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc-core-interceptors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- local.ch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -136,7 +136,9 @@ files:
|
|
136
136
|
- lib/lhc-core-interceptors/auth.rb
|
137
137
|
- lib/lhc-core-interceptors/caching.rb
|
138
138
|
- lib/lhc-core-interceptors/monitoring.rb
|
139
|
+
- lib/lhc-core-interceptors/railtie.rb
|
139
140
|
- lib/lhc-core-interceptors/rollbar.rb
|
141
|
+
- lib/lhc-core-interceptors/test/cache_helper.rb
|
140
142
|
- lib/lhc-core-interceptors/version.rb
|
141
143
|
- spec/auth/basic_auth_spec.rb
|
142
144
|
- spec/auth/bearer_spec.rb
|
@@ -210,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
212
|
requirements:
|
211
213
|
- Ruby >= 1.9.2
|
212
214
|
rubyforge_project:
|
213
|
-
rubygems_version: 2.
|
215
|
+
rubygems_version: 2.6.8
|
214
216
|
signing_key:
|
215
217
|
specification_version: 4
|
216
218
|
summary: A set of interceptors
|