Module: KMZCompressor::ControllerExtensions::InstanceMethods
- Defined in:
- lib/kmz_compressor/controller_extensions.rb
Instance Method Summary collapse
-
#render_202_while_caching(&action) ⇒ Object
Subsequent calls to this action return a 202 while the original result is being cached.
Instance Method Details
#render_202_while_caching(&action) ⇒ Object
Subsequent calls to this action return a 202 while the original result is being cached
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kmz_compressor/controller_extensions.rb', line 14 def render_202_while_caching(&action) cache_key = [:kmz_in_progress, Digest::SHA256.base64digest(params.inspect)] if Rails.cache.exist?(cache_key) render :status => 202, :nothing => true else begin Rails.cache.write(cache_key, true, :expires_in => 1.hour) # Expire in case we somehow leave the cache key behind action.call ensure Rails.cache.delete(cache_key) end end end |