Class: Force::Middleware::Caching

Inherits:
FaradayMiddleware::Caching
  • Object
show all
Defined in:
lib/force/middleware/caching.rb

Instance Method Summary collapse

Instance Method Details

#cache_key(env) ⇒ Object

We don't want to cache requests for different clients, so append the oauth token to the cache key.


14
15
16
# File 'lib/force/middleware/caching.rb', line 14

def cache_key(env)
  super(env) + env[:request_headers][Force::Middleware::Authorization::AUTH_HEADER].gsub(/\s/, '')
end

#call(env) ⇒ Object


3
4
5
6
# File 'lib/force/middleware/caching.rb', line 3

def call(env)
  expire(cache_key(env)) unless use_cache?
  super
end

#expire(key) ⇒ Object


8
9
10
# File 'lib/force/middleware/caching.rb', line 8

def expire(key)
  cache.delete(key) if cache
end

#use_cache?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/force/middleware/caching.rb', line 18

def use_cache?
  !@options.has_key?(:use_cache) || @options[:use_cache]
end