Class: RestCache::Middleware
- Inherits:
-
Object
- Object
- RestCache::Middleware
- Defined in:
- lib/rest_cache.rb
Constant Summary collapse
- EXPIRATION_SECONDS_DEFAULT =
300
- GLOBAL_CACHING_DEFAULT =
true
- @@cache =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
- #expire(path = nil) ⇒ Object
-
#initialize(app, options) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options) ⇒ Middleware
Returns a new instance of Middleware.
12 13 14 15 16 17 18 19 20 |
# File 'lib/rest_cache.rb', line 12 def initialize(app, ) # assign defaults to potentially missing options [:expiration_seconds] ||= EXPIRATION_SECONDS_DEFAULT [:global] &&= GLOBAL_CACHING_DEFAULT @app = app @options = end |
Class Method Details
.expire(path = nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/rest_cache.rb', line 46 def self.expire(path=nil) if path purge_path path else purge_all end end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rest_cache.rb', line 22 def call(env) @request = Rack::Request.new(env) if @request.get? get(env) else # expire all cached items for this request expire(@request.fullpath.gsub(/\.(.*)$/, '')) # strip the format, if present # pass along the call @app.call(env) end end |
#expire(path = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rest_cache.rb', line 38 def expire(path=nil) if path purge_path path else purge_all end end |