Coder Social home page Coder Social logo

response_bank's Issues

browser can't decompress

this gem was working fine, I was using this gem few months ago

but now I am getting this error:

image

it's like the body is dumped, but not rendered correctly on browser side
I have tried few times to call render method in response_cache's block argument

Incompatible with latest mocha gem

% 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.

@rafaelfranca

Documentation please?

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!

Use this in an API Controller?

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?

Error pages other than 404s are uncacheable

Currently, response_bank only caches pages if the response code is a 200, 301, or 404:

if [200, 404, 301].include?(status) && env['cacheable.miss']

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.

Is there external Documentation or a Case Study on this gem?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.