about summary refs log tree commit diff
path: root/app/controllers/application_controller.rb
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2017-12-30 18:24:38 -0600
committerGitHub <noreply@github.com>2017-12-30 18:24:38 -0600
commitd817c0a958efda990af654f72d15d6f42b43dd49 (patch)
tree0cff3632163fadeba3585f56ecdd8d1d919e12c7 /app/controllers/application_controller.rb
parent65c87ca0ae20eb5dc62751047bda3e8b11e37ce0 (diff)
parent4cca1d1e7efce51eecb64489f412a7b8631f0aed (diff)
Merge pull request #291 from glitch-soc/merge-upstream
Merge with upstream @ f4b80e6511f21b60f71ed182bb66ca6ef0ba9f66
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r--app/controllers/application_controller.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 3b2070f39..46367f202 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -196,4 +196,13 @@ class ApplicationController < ActionController::Base
       end
     end
   end
+
+  def render_cached_json(cache_key, **options)
+    data = Rails.cache.fetch(cache_key, { raw: true }.merge(options)) do
+      yield.to_json
+    end
+
+    expires_in options[:expires_in], public: true
+    render json: data
+  end
 end