lhc-core-interceptors 2.3.3 → 2.4.0

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
  SHA1:
3
- metadata.gz: 41a327e82cedde8f9a8cb963a4a8fc54dee0af82
4
- data.tar.gz: 9b70cd9f309331568cf6971bbd41900d9789945f
3
+ metadata.gz: 06055f3a1962c8675da6aa73da1256fbe733e02f
4
+ data.tar.gz: c504a736602334e94a6f5ddbc6d55e5eee46fc13
5
5
  SHA512:
6
- metadata.gz: 3112435d52a728e58bf778c51b89d54460405b087b15e54e7bef47f4818f936e010da2ea4548ffeae2652a0d37fb1d5675d3c1b2ce215128ccb9a46fbe408525
7
- data.tar.gz: 2f9eb72998ae26b16a164fa9ba3f1feffe920843cf20b0fde40e332850c1c99ca3603c1f93d059cf1709ea3c776e84791b66c10a7135083b779da8fd37ca9204
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
- Gem.find_files('lhc-core-interceptors/**/*.rb').sort.each { |path| require path }
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 = Rails.cache.fetch(key(request))
17
+ cached_response_data = cache.fetch(key(request))
14
18
  return unless cached_response_data
15
- Rails.logger.info "Served from cache: #{key(request)}"
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
- Rails.cache.write(key(request), to_cache(response), options(request.options))
27
+ cache.write(key(request), to_cache(response), options(request.options))
23
28
  end
24
29
 
25
30
  private
@@ -0,0 +1,8 @@
1
+ module LhcCoreInterceptors
2
+ class Railtie < Rails::Railtie
3
+ initializer "lhc.configure_rails_initialization" do
4
+ LHC::Caching.cache ||= Rails.cache
5
+ LHC::Caching.logger ||= Rails.logger
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.configure do |config|
2
+ LHC::Caching.cache = ActiveSupport::Cache::MemoryStore.new
3
+
4
+ config.before(:each) do
5
+ LHC::Caching.cache.clear
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module LHCCoreInterceptors
2
- VERSION = '2.3.3'
2
+ VERSION = '2.4.0'
3
3
  end
@@ -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.serve_static_assets = false
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.serve_static_assets = true
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.3.3
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: 2016-11-30 00:00:00.000000000 Z
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.4.6
215
+ rubygems_version: 2.6.8
214
216
  signing_key:
215
217
  specification_version: 4
216
218
  summary: A set of interceptors