-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.rb
45 lines (31 loc) · 916 Bytes
/
cache.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'faraday'
require 'faraday/cache/middleware'
require 'faraday/cache/request'
require 'faraday/cache/response'
require 'faraday/cache/abstract_store'
require 'faraday/cache/memory_store'
class Faraday::Cache
VERSION = '0.0.1'
Error = Class.new StandardError
UnsupportedAdapter = Class.new Error
attr_reader :backend
def initialize(options = {})
@backend = options[:backend] || MemoryStore.new(options)
end
def store(request, response)
backend.store(request, response) if response.cacheable?
end
def fetch(request)
backend.fetch(request)
end
def invalidate(request)
end
def set_conditional_headers!(request, response)
if etag = response.headers['ETag']
request.headers['If-None-Match'] = etag
end
if last_modified = response.headers['Last-Modified']
request.headers['If-Modified-Since'] = last_modified
end
end
end