api-response-cache 0.1.2 → 0.2.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/lib/api-response-cache.rb +11 -0
- data/lib/api_response_cache/api_cache_handler.rb +11 -3
- data/lib/api_response_cache/config.rb +14 -0
- data/lib/api_response_cache/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42381b180cd364cf42447e4d5a611442a1e89d705203c1d5f778b3f53cf918cc
|
4
|
+
data.tar.gz: 82d5d1b775456abd9e8b50a0d7c70f4d169d34b7ce03d2158a697c0865f52a06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a0aa8082523581177755e9b0068a41d178f71741b76cc598969b13a5c5827c4a0801aff021b3bb24b8f6368fea8191cd157e04d940454c549d79224f252f9ca
|
7
|
+
data.tar.gz: a33a843bf730cd690f9a71b0743feeb5b8dacb68882d6ea16937d35cbff8051f75294a0003d5357c46b3e72a8c2cd250cf737ae00d952a65ff7dccaa2f88dc4c
|
data/lib/api-response-cache.rb
CHANGED
@@ -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 =
|
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
|
-
@
|
32
|
+
@processor_name = "#{@controller.class.name}##{@controller.action_name}"
|
33
|
+
@response_cache = ResponseCache.new(cache_path, @expires_in)
|
34
|
+
end
|
33
35
|
|
34
|
-
|
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
|
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.
|
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
|