Shopify/response_bank
Simple response caching for Ruby applications
{ "createdAt": "2008-04-21T18:25:42Z", "defaultBranch": "main", "description": "Simple response caching for Ruby applications", "fullName": "Shopify/response_bank", "homepage": "http://www.shopify.com", "language": "Ruby", "name": "response_bank", "pushedAt": "2025-10-24T18:32:23Z", "stargazersCount": 136, "topics": [], "updatedAt": "2025-10-10T12:19:52Z", "url": "https://github.com/Shopify/response_bank"}ResponseBank

Section titled “ResponseBank ”Features
Section titled “Features”- Serve gzip’d content
- Add ETag and 304 Not Modified headers
- Generational caching
- No explicit expiry
Support
Section titled “Support”This gem supports the following versions of Ruby and Rails:
- Ruby 2.7.0+
- Rails 6.0.0+
-
include the gem in your Gemfile
gem 'response_bank' -
add an initializer file. We need to configure the
acquire_lockmethod, set the cache store and the loggerrequire 'response_bank'module ResponseBankLOCK_TTL = 90class << selfdef acquire_lock(cache_key)cache_store.write("#{cache_key}:lock", '1', unless_exist: true, expires_in: LOCK_TTL, raw: true)endendendResponseBank.cache_store = ActiveSupport::Cache.lookup_store(Rails.configuration.cache_store)ResponseBank.logger = Rails.logger -
enables caching on your application
config.action_controller.perform_caching = true -
use
#response_cachemethod to any desired controller’s actionclass PostsController < ApplicationControllerdef showresponse_cache do@post = @shop.posts.find(params[:id])respond_with(@post)endendend -
(optional) set a custom TTL for the cache by overriding the
write_to_backing_cache_storemethod in your initializer filemodule ResponseBankCACHE_TTL = 30.minutesdef write_to_backing_cache_store(_env, key, payload, expires_in: nil)cache_store.write(key, payload, raw: true, expires_in: expires_in || CACHE_TTL)endend -
(optional) override custom cache key data. For default, cache key is defined by URL and query string
class PostsController < ApplicationControllerbefore_action :set_shopdef indexresponse_cache do@post = @shop.postsrespond_with(@post)endenddef showresponse_cache do@post = @shop.posts.find(params[:id])respond_with(@post)endenddef another_action# custom cache key datacache_key = {action: action_name,format: request.format,shop_updated_at: @shop.updated_at# you may add more keys here}response_cache cache_key do@post = @shop.posts.find(params[:id])respond_with(@post)endend# override default cache key data globally per classdef cache_key_data{action: action_name,format: request.format,params: params.slice(:id),shop_version: @shop.version# you may add more keys here}enddef set_shop# @shop = ...endend
License
Section titled “License”ResponseBank is released under the [MIT License]!(LICENSE.txt).