api-response-cache 0.1.2 → 0.2.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
  SHA256:
3
- metadata.gz: 148d7d9bfff313cdedbef1f0526d3d6ee64f537ce07e867255b2d705d370de79
4
- data.tar.gz: ba3b9d987f6c7456965296480b51c0a76457432d7d1b72ad199408c79f2c3eda
3
+ metadata.gz: 42381b180cd364cf42447e4d5a611442a1e89d705203c1d5f778b3f53cf918cc
4
+ data.tar.gz: 82d5d1b775456abd9e8b50a0d7c70f4d169d34b7ce03d2158a697c0865f52a06
5
5
  SHA512:
6
- metadata.gz: 6f89a6ba882a02df2e768e935705652a87f494b3e6e85c9207cbbcf213d3aee3456d5ae5963890e1bc8dba3b8662afbfeb1acc467765eb862b3cce2de7eb41e0
7
- data.tar.gz: 207ee649ce350aa6eada137d722cd2467b440a8f9c8e22ac7f005a2c071fecfae2decbbd928397a31a74a6ef5099f0a0e7281f2709c118450ff50a377be1b496
6
+ metadata.gz: 2a0aa8082523581177755e9b0068a41d178f71741b76cc598969b13a5c5827c4a0801aff021b3bb24b8f6368fea8191cd157e04d940454c549d79224f252f9ca
7
+ data.tar.gz: a33a843bf730cd690f9a71b0743feeb5b8dacb68882d6ea16937d35cbff8051f75294a0003d5357c46b3e72a8c2cd250cf737ae00d952a65ff7dccaa2f88dc4c
@@ -4,5 +4,16 @@ require "api_response_cache/version"
4
4
  require "api_response_cache/actions"
5
5
  require "api_response_cache/api_cache_handler"
6
6
  require "api_response_cache/response_cache"
7
+ require "api_response_cache/config"
7
8
 
8
9
  ActionController::API.send(:include, ApiResponseCache::Actions)
10
+
11
+ module ApiResponseCache
12
+ def self.configure
13
+ yield configuration
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= ApiResponseCache::Config.new
18
+ end
19
+ end
@@ -21,7 +21,7 @@ module ApiResponseCache
21
21
  protected
22
22
 
23
23
  def log_info
24
- processor = Rainbow("#{@controller.class.name}##{@controller.action_name}").blue
24
+ processor = @processor_name.blue
25
25
  responder = Rainbow('API Response Cache').green
26
26
  Rails.logger.info "=== #{processor} response by #{responder} ==="
27
27
  end
@@ -29,9 +29,17 @@ module ApiResponseCache
29
29
  def init(controller)
30
30
  @controller = controller
31
31
  @request = controller.request
32
- @cache_path ||= "api-response-cache/#{@options[:cache_path] || @request.fullpath}"
32
+ @processor_name = "#{@controller.class.name}##{@controller.action_name}"
33
+ @response_cache = ResponseCache.new(cache_path, @expires_in)
34
+ end
33
35
 
34
- @response_cache = ResponseCache.new(@cache_path, @expires_in)
36
+ def cache_path
37
+ return @cache_path if @cache_path.present?
38
+ @cache_path = "api-response-cache/#{@processor_name || @options[:cache_path]}"
39
+ if ApiResponseCache.configuration.refresh_by_request_params?
40
+ @cache_path = "#{@cache_path}/#{@request.fullpath}"
41
+ end
42
+ @cache_path
35
43
  end
36
44
 
37
45
  def render_cached_response
@@ -0,0 +1,14 @@
1
+ module ApiResponseCache
2
+ class Config
3
+ attr_accessor :refresh_by_request_params
4
+
5
+ def initialize
6
+ @refresh_by_request_params = false
7
+ end
8
+
9
+
10
+ def refresh_by_request_params?
11
+ refresh_by_request_params
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module ApiResponseCache
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-response-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uysim Ty
@@ -71,6 +71,7 @@ files:
71
71
  - lib/api-response-cache.rb
72
72
  - lib/api_response_cache/actions.rb
73
73
  - lib/api_response_cache/api_cache_handler.rb
74
+ - lib/api_response_cache/config.rb
74
75
  - lib/api_response_cache/response_cache.rb
75
76
  - lib/api_response_cache/version.rb
76
77
  homepage: http://uysim.com