shopify / response_bank Goto Github PK
View Code? Open in Web Editor NEWThis project forked from tobi/cacheable
Simple response caching for Ruby applications
Home Page: http://www.shopify.com
License: MIT License
This project forked from tobi/cacheable
Simple response caching for Ruby applications
Home Page: http://www.shopify.com
License: MIT License
% bundle install
% bundle exec rake
...
File does not exist: mocha/mini_test
Caused by transitive dependency on mocha
which has made an incompatible change, but there doesn't appear to be anything pinning it.
Could you perhaps share a short example of how to use the gem?
So far I get the idea that you add include Cacheable::Controller
in a controller... it's a little challenging to decipher without some direction though. Thanks!
I'm not 100% sure this is intended use, but I just bodged my way into adding this to a API controller, and it appears to work. The error that I hit when I first tried was:
A NoMethodError occurred in titles#show:
undefined method `cache_configured?' for #<Api::V1::TitlesController:0x0000000003e7d8>
unless cache_configured? && cacheable_req
^^^^^^^^^^^^^^^^^
Did you mean? cache_version_data
app/controllers/api/v1/titles_controller.rb:9:in `show'
(Rails 7.0.8.1)
And that's confusing, unless this line doesn't do what I imagine it does.
Which led me down the way to a bit of example code in one of the tests, which seems to also work in my API controller. I wonder if this leaves anything out that the other controllers get? All the other (non-API) routes seem to work just fine.
module Api
module V1
class TitlesController < ActionController::API
helper ApplicationHelper, PeopleHelper
include ResponseBank::Controller # <--- this
def show
response_cache do
@title = Title.published.includes(:headings, :roles, :collections).friendly.find(params[:id])
end
end
private
# and this method
def cache_configured?
true
end
end
end
end
I'm going to try this in production for a couple of minutes, but are there any alarm bells going off for you?
Currently, response_bank
only caches pages if the response code is a 200, 301, or 404:
This prevents response_bank
from being used to cache error pages other than 404s, even though caching other error pages (such as 429s) would bring the same performance benefits as caching 404 pages.
For example, only the 404 error page would be cached in this example:
class ErrorsController < ApplicationController
def not_found
response_cache(error_code: 404) do
render(template: "errors/not_found", status: :not_found)
end
end
def too_many_requests
response_cache(error_code: 429) do
render(template: "errors/too_many_requests", status: :too_many_requests)
end
end
def internal_server_error
response_cache(error_code: 500) do
render(template: "errors/internal_server_error", status: :internal_server_error)
end
end
end
Caching responses with other error status codes that may depend on the state of the client (e.g. 429s depend on how many times the client has already hit the server) can be tricky, so I would suggest allowing response_bank
to accept a configuration option that overrides the default array of cacheable response codes.
Please see https://github.com/Shopify/shopify-app-store/issues/17194 and https://github.com/Shopify/shopify-app-store/pull/17365/files#r901784102 and for more context on why App Store and Theme Store could use this change.
Hey this gem looks very useful. I've been googling around and trying to find an article on this gem of the ROI Shopify has seen by using it or any other company. So far I've been unsuccessful.
Does anyone know of any external documentation for case study's for this gem?
I see a similar question was asked back in 2013 but the link doesn't exist anymore: #8
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.