diff --git a/Gemfile b/Gemfile index 2ac3466..1cbb79b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ # frozen_string_literal: true source "https://rubygems.org" -# Specify your gem's dependencies in cacheable.gemspec +# Specify your gem's dependencies in response_bank.gemspec gemspec gem 'rails', '~> 6.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 0ce6af4..ed511b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - cacheable (2.0.0) + response_bank (1.0.0) msgpack useragent @@ -156,11 +156,11 @@ PLATFORMS ruby DEPENDENCIES - cacheable! minitest (>= 5.13.0) mocha (>= 1.10.0) rails (~> 6.0.0) rake + response_bank! rubocop (= 0.78.0) tzinfo-data (>= 1.2019.3) diff --git a/README.md b/README.md index c68e23f..940d743 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Cacheable [![Build Status](https://secure.travis-ci.org/Shopify/cacheable.png)](http://travis-ci.org/Shopify/cacheable) +# ResponseBank [![Build Status](https://secure.travis-ci.org/Shopify/response_bank.png)](http://travis-ci.org/Shopify/response_bank) ### Features @@ -19,7 +19,7 @@ This gem supports the following versions of Ruby and Rails: 1. include the gem in your Gemfile ```ruby -gem 'cacheable' +gem 'response_bank' ``` 2. use `#response_cache` method to any desired controller's action @@ -83,9 +83,9 @@ class PostsController < ApplicationController def set_shop # @shop = ... end -end +end ``` ### License -Cacheable is released under the [MIT License](LICENSE.txt). +ResponseBank is released under the [MIT License](LICENSE.txt). diff --git a/lib/cacheable/version.rb b/lib/cacheable/version.rb deleted file mode 100644 index 9f99c7f..0000000 --- a/lib/cacheable/version.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true -module Cacheable - VERSION = "2.0.0" -end diff --git a/lib/cacheable.rb b/lib/response_bank.rb similarity index 80% rename from lib/cacheable.rb rename to lib/response_bank.rb index 6f23053..8e3f8f1 100644 --- a/lib/cacheable.rb +++ b/lib/response_bank.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require 'cacheable/middleware' -require 'cacheable/railtie' if defined?(Rails) -require 'cacheable/response_cache_handler' +require 'response_bank/middleware' +require 'response_bank/railtie' if defined?(Rails) +require 'response_bank/response_cache_handler' require 'msgpack' -module Cacheable +module ResponseBank class << self attr_accessor :cache_store attr_writer :logger def log(message) - @logger.info("[Cacheable] #{message}") + @logger.info("[ResponseBank] #{message}") end def acquire_lock(_cache_key) - raise NotImplementedError, "Override Cacheable.acquire_lock in an initializer." + raise NotImplementedError, "Override ResponseBank.acquire_lock in an initializer." end def write_to_cache(_key) diff --git a/lib/cacheable/controller.rb b/lib/response_bank/controller.rb similarity index 89% rename from lib/cacheable/controller.rb rename to lib/response_bank/controller.rb index 6b68378..e6cc2d7 100644 --- a/lib/cacheable/controller.rb +++ b/lib/response_bank/controller.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -module Cacheable +module ResponseBank module Controller private - # Only get? and head? requests should be cacheable + # Only get? and head? requests should be cached. def cacheable_request? (request.get? || request.head?) && (request.params[:cache] != 'false') end @@ -35,13 +35,13 @@ def response_cache(key_data = nil, version_data = nil, &block) cacheable_req = cacheable_request? unless cache_configured? && cacheable_req - Cacheable.log("Uncacheable request. cache_configured='#{!!cache_configured?}'" \ + ResponseBank.log("Uncacheable request. cache_configured='#{!!cache_configured?}'" \ " cacheable_request='#{cacheable_req}' params_cache='#{request.params[:cache] != 'false'}'") response.headers['Cache-Control'] = 'no-cache, no-store' unless cacheable_req return yield end - handler = Cacheable::ResponseCacheHandler.new( + handler = ResponseBank::ResponseCacheHandler.new( key_data: key_data || cache_key_data, version_data: version_data || cache_version_data, env: request.env, diff --git a/lib/cacheable/middleware.rb b/lib/response_bank/middleware.rb similarity index 87% rename from lib/cacheable/middleware.rb rename to lib/response_bank/middleware.rb index 7d6f66c..35e06a5 100644 --- a/lib/cacheable/middleware.rb +++ b/lib/response_bank/middleware.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'useragent' -module Cacheable +module ResponseBank class Middleware REQUESTED_WITH = "HTTP_X_REQUESTED_WITH" ACCEPT = "HTTP_ACCEPT" @@ -36,18 +36,18 @@ def call(env) body.each { |part| body_string << part } end - body_gz = Cacheable.compress(body_string) + body_gz = ResponseBank.compress(body_string) # Store result cache_data = [status, headers['Content-Type'], body_gz, timestamp] cache_data << headers['Location'] if status == 301 - Cacheable.write_to_cache(env['cacheable.key']) do + ResponseBank.write_to_cache(env['cacheable.key']) do payload = MessagePack.dump(cache_data) - Cacheable.cache_store.write(env['cacheable.key'], payload, raw: true) + ResponseBank.cache_store.write(env['cacheable.key'], payload, raw: true) if env['cacheable.unversioned-key'] - Cacheable.cache_store.write(env['cacheable.unversioned-key'], payload, raw: true) + ResponseBank.cache_store.write(env['cacheable.unversioned-key'], payload, raw: true) end end diff --git a/lib/cacheable/model_extensions.rb b/lib/response_bank/model_extensions.rb similarity index 94% rename from lib/cacheable/model_extensions.rb rename to lib/response_bank/model_extensions.rb index 486b595..70fef46 100644 --- a/lib/cacheable/model_extensions.rb +++ b/lib/response_bank/model_extensions.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -module Cacheable +module ResponseBank module ModelExtensions def self.included(base) super diff --git a/lib/cacheable/railtie.rb b/lib/response_bank/railtie.rb similarity index 52% rename from lib/cacheable/railtie.rb rename to lib/response_bank/railtie.rb index 6688344..b93c236 100644 --- a/lib/cacheable/railtie.rb +++ b/lib/response_bank/railtie.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true require 'rails' -require 'cacheable/controller' -require 'cacheable/model_extensions' +require 'response_bank/controller' +require 'response_bank/model_extensions' -module Cacheable +module ResponseBank class Railtie < ::Rails::Railtie initializer "cachable.configure_active_record" do |config| - config.middleware.insert_after(Rack::Head, Cacheable::Middleware) + config.middleware.insert_after(Rack::Head, ResponseBank::Middleware) ActiveSupport.on_load(:action_controller) do - include Cacheable::Controller + include ResponseBank::Controller end ActiveSupport.on_load(:active_record) do - include Cacheable::ModelExtensions + include ResponseBank::ModelExtensions end end end diff --git a/lib/cacheable/response_cache_handler.rb b/lib/response_bank/response_cache_handler.rb similarity index 84% rename from lib/cacheable/response_cache_handler.rb rename to lib/response_bank/response_cache_handler.rb index 2b66c2d..e4166c4 100644 --- a/lib/cacheable/response_cache_handler.rb +++ b/lib/response_bank/response_cache_handler.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'digest/md5' -module Cacheable +module ResponseBank class ResponseCacheHandler def initialize( key_data:, @@ -11,7 +11,7 @@ def initialize( serve_unversioned:, headers:, force_refill_cache: false, - cache_store: Cacheable.cache_store, + cache_store: ResponseBank.cache_store, &block ) @cache_miss_block = block @@ -32,7 +32,7 @@ def run! @env['cacheable.key'] = versioned_key_hash @env['cacheable.unversioned-key'] = unversioned_key_hash - Cacheable.log(cacheable_info_dump) + ResponseBank.log(cacheable_info_dump) if @force_refill_cache refill_cache @@ -56,11 +56,11 @@ def key_hash(key) end def versioned_key - @versioned_key ||= Cacheable.cache_key_for(key: @key_data, version: @version_data) + @versioned_key ||= ResponseBank.cache_key_for(key: @key_data, version: @version_data) end def unversioned_key - @unversioned_key ||= Cacheable.cache_key_for(key: @key_data) + @unversioned_key ||= ResponseBank.cache_key_for(key: @key_data) end def cacheable_info_dump @@ -93,7 +93,7 @@ def try_to_serve_from_cache @env['cacheable.locked'] ||= false - if @env['cacheable.locked'] || Cacheable.acquire_lock(versioned_key_hash) + if @env['cacheable.locked'] || ResponseBank.acquire_lock(versioned_key_hash) # execute if we can get the lock @env['cacheable.locked'] = true elsif serving_from_noncurrent_but_recent_version_acceptable? @@ -120,7 +120,7 @@ def serve_from_browser_cache(cache_key_hash) @headers.delete('Content-Type') @headers.delete('Content-Length') - Cacheable.log("Cache hit: client") + ResponseBank.log("Cache hit: client") [304, @headers, []] end @@ -138,7 +138,7 @@ def serve_from_cache(cache_key_hash, message, cache_age_tolerance = nil) status, content_type, body, timestamp, location = hit if cache_age_tolerance && page_too_old?(timestamp, cache_age_tolerance) - Cacheable.log("Found an unversioned cache entry, but it was too old (#{timestamp})") + ResponseBank.log("Found an unversioned cache entry, but it was too old (#{timestamp})") nil else @@ -150,11 +150,11 @@ def serve_from_cache(cache_key_hash, message, cache_age_tolerance = nil) @headers['Content-Encoding'] = "gzip" else # we have to uncompress because the client doesn't support gzip - Cacheable.log("uncompressing for client without gzip") - body = Cacheable.decompress(body) + ResponseBank.log("uncompressing for client without gzip") + body = ResponseBank.decompress(body) end - Cacheable.log(message) + ResponseBank.log(message) [status, @headers, [body]] end @@ -168,7 +168,7 @@ def page_too_old?(timestamp, cache_age_tolerance) def refill_cache @env['cacheable.miss'] = true - Cacheable.log("Refilling cache") + ResponseBank.log("Refilling cache") @cache_miss_block.call end diff --git a/lib/response_bank/version.rb b/lib/response_bank/version.rb new file mode 100644 index 0000000..f3df2ba --- /dev/null +++ b/lib/response_bank/version.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true +module ResponseBank + VERSION = "1.0.0" +end diff --git a/cacheable.gemspec b/response_bank.gemspec similarity index 80% rename from cacheable.gemspec rename to response_bank.gemspec index 5adb9f0..d4807e0 100644 --- a/cacheable.gemspec +++ b/response_bank.gemspec @@ -1,17 +1,16 @@ # -*- encoding: utf-8 -*- # frozen_string_literal: true $LOAD_PATH.push(File.expand_path("../lib", __FILE__)) -require "cacheable/version" +require "response_bank/version" Gem::Specification.new do |s| - s.name = "cacheable" - s.version = Cacheable::VERSION + s.name = "response_bank" + s.version = ResponseBank::VERSION s.license = "MIT" s.authors = ["Tobias Lütke", "Burke Libbey"] s.email = ["tobi@shopify.com", "burke@burkelibbey.org"] s.homepage = "" - s.summary = 'Simple rails request caching' - s.description = 'Simple rails request caching' + s.summary = 'Simple response caching for Ruby applications' s.files = Dir["lib/**/*.rb", "README.md", "LICENSE.txt"] s.require_paths = ["lib"] diff --git a/test/controller_test.rb b/test/controller_test.rb index c796397..b2f9465 100644 --- a/test/controller_test.rb +++ b/test/controller_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require File.dirname(__FILE__) + "/test_helper" -class CacheableControllerTest < Minitest::Test +class ResponseBankControllerTest < Minitest::Test class MockRequest def get? true @@ -23,7 +23,7 @@ def headers end class MockController - include Cacheable::Controller + include ResponseBank::Controller def cache_configured? true @@ -44,8 +44,8 @@ def response def setup @cache_store = stub.tap { |s| s.stubs(read: nil) } - Cacheable.cache_store = @cache_store - Cacheable.stubs(:acquire_lock).returns(true) + ResponseBank.cache_store = @cache_store + ResponseBank.stubs(:acquire_lock).returns(true) end def test_cache_control_no_store_set_for_uncacheable_requests @@ -64,7 +64,7 @@ def test_server_cache_hit def test_client_cache_hit controller.request.env['HTTP_IF_NONE_MATCH'] = 'deadbeef' - Cacheable::ResponseCacheHandler.any_instance.expects(:versioned_key_hash).returns('deadbeef').at_least_once + ResponseBank::ResponseCacheHandler.any_instance.expects(:versioned_key_hash).returns('deadbeef').at_least_once controller.expects(:head).with(:not_modified) controller.send(:response_cache) {} @@ -77,6 +77,6 @@ def controller end def page_serialized - MessagePack.dump([200, "text/html", Cacheable.compress("hi."), 1331765506]) + MessagePack.dump([200, "text/html", ResponseBank.compress("hi."), 1331765506]) end end diff --git a/test/middleware_test.rb b/test/middleware_test.rb index a8c5af9..6624417 100644 --- a/test/middleware_test.rb +++ b/test/middleware_test.rb @@ -8,7 +8,7 @@ def logger end Rails.singleton_class.prepend(EmptyLogger) -Cacheable.cache_store = ActiveSupport::Cache.lookup_store(:memory_store) +ResponseBank.cache_store = ActiveSupport::Cache.lookup_store(:memory_store) def app(_env) body = block_given? ? [yield] : ['Hi'] @@ -74,29 +74,29 @@ class MiddlewareTest < Minitest::Test def test_cache_miss_and_ignore env = Rack::MockRequest.env_for("http://example.com/index.html") - ware = Cacheable::Middleware.new(method(:app)) + ware = ResponseBank::Middleware.new(method(:app)) result = ware.call(env) assert_nil(result[1]['ETag']) end def test_cache_miss_and_not_found - Cacheable.cache_store.expects(:write).once + ResponseBank.cache_store.expects(:write).once env = Rack::MockRequest.env_for("http://example.com/index.html") - ware = Cacheable::Middleware.new(method(:not_found)) + ware = ResponseBank::Middleware.new(method(:not_found)) result = ware.call(env) assert_equal('"abcd"', result[1]['ETag']) end def test_cache_hit_and_moved - Cacheable.cache_store.expects(:write).never + ResponseBank.cache_store.expects(:write).never env = Rack::MockRequest.env_for("http://example.com/index.html") - ware = Cacheable::Middleware.new(method(:cached_moved)) + ware = ResponseBank::Middleware.new(method(:cached_moved)) result = ware.call(env) assert_equal('"abcd"', result[1]['ETag']) @@ -104,10 +104,10 @@ def test_cache_hit_and_moved end def test_cache_miss_and_moved - Cacheable.cache_store.expects(:write).once + ResponseBank.cache_store.expects(:write).once env = Rack::MockRequest.env_for("http://example.com/index.html") - ware = Cacheable::Middleware.new(method(:moved)) + ware = ResponseBank::Middleware.new(method(:moved)) result = ware.call(env) assert_equal('"abcd"', result[1]['ETag']) @@ -115,16 +115,16 @@ def test_cache_miss_and_moved end def test_cache_miss_and_store - Cacheable::Middleware.any_instance.stubs(timestamp: 424242) - Cacheable.cache_store.expects(:write).with( + ResponseBank::Middleware.any_instance.stubs(timestamp: 424242) + ResponseBank.cache_store.expects(:write).with( '"abcd"', - MessagePack.dump([200, 'text/plain', Cacheable.compress('Hi'), 424242]), + MessagePack.dump([200, 'text/plain', ResponseBank.compress('Hi'), 424242]), raw: true ).once env = Rack::MockRequest.env_for("http://example.com/index.html") - ware = Cacheable::Middleware.new(method(:cacheable_app)) + ware = ResponseBank::Middleware.new(method(:cacheable_app)) result = ware.call(env) assert(env['cacheable.cache']) @@ -139,16 +139,16 @@ def test_cache_miss_and_store end def test_cache_miss_and_store_on_moved - Cacheable::Middleware.any_instance.stubs(timestamp: 424242) - Cacheable.cache_store.expects(:write).with( + ResponseBank::Middleware.any_instance.stubs(timestamp: 424242) + ResponseBank.cache_store.expects(:write).with( '"abcd"', - MessagePack.dump([301, 'text/plain', Cacheable.compress(''), 424242, 'http://shopify.com']), + MessagePack.dump([301, 'text/plain', ResponseBank.compress(''), 424242, 'http://shopify.com']), raw: true ).once env = Rack::MockRequest.env_for("http://example.com/index.html") - ware = Cacheable::Middleware.new(method(:moved)) + ware = ResponseBank::Middleware.new(method(:moved)) result = ware.call(env) assert(env['cacheable.cache']) @@ -163,17 +163,17 @@ def test_cache_miss_and_store_on_moved end def test_cache_miss_and_store_with_gzip_support - Cacheable::Middleware.any_instance.stubs(timestamp: 424242) - Cacheable.cache_store.expects(:write).with( + ResponseBank::Middleware.any_instance.stubs(timestamp: 424242) + ResponseBank.cache_store.expects(:write).with( '"abcd"', - MessagePack.dump([200, 'text/plain', Cacheable.compress('Hi'), 424242]), + MessagePack.dump([200, 'text/plain', ResponseBank.compress('Hi'), 424242]), raw: true ).once env = Rack::MockRequest.env_for("http://example.com/index.html") env['HTTP_ACCEPT_ENCODING'] = 'deflate, gzip' - ware = Cacheable::Middleware.new(method(:cacheable_app)) + ware = ResponseBank::Middleware.new(method(:cacheable_app)) result = ware.call(env) assert(env['cacheable.cache']) @@ -185,15 +185,15 @@ def test_cache_miss_and_store_with_gzip_support # gzip support! assert_equal('gzip', result[1]['Content-Encoding']) - assert_equal([Cacheable.compress("Hi")], result[2]) + assert_equal([ResponseBank.compress("Hi")], result[2]) end def test_cache_hit_server - Cacheable.cache_store.expects(:write).times(0) + ResponseBank.cache_store.expects(:write).times(0) env = Rack::MockRequest.env_for("http://example.com/index.html") - ware = Cacheable::Middleware.new(method(:already_cached_app)) + ware = ResponseBank::Middleware.new(method(:already_cached_app)) result = ware.call(env) assert(env['cacheable.cache']) @@ -203,11 +203,11 @@ def test_cache_hit_server end def test_cache_hit_client - Cacheable.cache_store.expects(:write).times(0) + ResponseBank.cache_store.expects(:write).times(0) env = Rack::MockRequest.env_for("http://example.com/index.html") - ware = Cacheable::Middleware.new(method(:client_hit_app)) + ware = ResponseBank::Middleware.new(method(:client_hit_app)) result = ware.call(env) assert(env['cacheable.cache']) @@ -217,7 +217,7 @@ def test_cache_hit_client end def test_ie_ajax - ware = Cacheable::Middleware.new(method(:already_cached_app)) + ware = ResponseBank::Middleware.new(method(:already_cached_app)) env = Rack::MockRequest.env_for("http://example.com/index.html") assert(!ware.send(:ie_ajax_request?, env)) @@ -241,13 +241,13 @@ def test_ie_ajax end def test_cache_hit_server_with_ie_ajax - Cacheable.cache_store.expects(:write).times(0) + ResponseBank.cache_store.expects(:write).times(0) env = Rack::MockRequest.env_for("http://example.com/index.html") env["HTTP_USER_AGENT"] = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" env["HTTP_X_REQUESTED_WITH"] = "XmlHttpRequest" - ware = Cacheable::Middleware.new(method(:already_cached_app)) + ware = ResponseBank::Middleware.new(method(:already_cached_app)) result = ware.call(env) assert(env['cacheable.cache']) diff --git a/test/rails_integration_test.rb b/test/rails_integration_test.rb index 439b049..89b5a00 100644 --- a/test/rails_integration_test.rb +++ b/test/rails_integration_test.rb @@ -17,7 +17,7 @@ class Base class RailsIntegrationTest < Minitest::Test def test_middleware_is_included - assert_includes(Dummy::Application.middleware, Cacheable::Middleware) + assert_includes(Dummy::Application.middleware, ResponseBank::Middleware) end def test_active_record_has_a_cache_store @@ -26,6 +26,6 @@ def test_active_record_has_a_cache_store end def test_action_controller_includes_cacheable - assert_includes(ActionController::Base, Cacheable::Controller) + assert_includes(ActionController::Base, ResponseBank::Controller) end end diff --git a/test/cacheable_test.rb b/test/response_bank_test.rb similarity index 82% rename from test/cacheable_test.rb rename to test/response_bank_test.rb index 603aa95..76ad2f3 100644 --- a/test/cacheable_test.rb +++ b/test/response_bank_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require File.dirname(__FILE__) + "/test_helper" -class CacheableTest < Minitest::Test +class ResponseBankTest < Minitest::Test def setup @data = { :foo => 'bar', @@ -19,17 +19,17 @@ def setup def test_cache_key_for_handles_nested_everything_and_removes_hash_keys_with_nil_values expected = %|bar,1,a,b,2,{:baz=>\"buzz\"},{:red=>[\"blue\", \"green\"], :day=>true, :night=>nil, :updated_at=>2011-06-29 15:47:47 UTC, :published_on=>Wed, 29 Jun 2011},text/html| # rubocop:disable Metrics/LineLength - assert_equal(expected, Cacheable.cache_key_for(key: @data)) + assert_equal(expected, ResponseBank.cache_key_for(key: @data)) end def test_cache_key_with_no_key_key expected = %|{:foo=>\"bar\", :bar=>[1, [\"a\", \"b\"], 2, {:baz=>\"buzz\"}], \"qux\"=>{:red=>[\"blue\", \"green\"], :day=>true, :night=>nil, :updated_at=>2011-06-29 15:47:47 UTC, :published_on=>Wed, 29 Jun 2011}}| # rubocop:disable Metrics/LineLength - assert_equal(expected, Cacheable.cache_key_for(@data.tap { |h| h.delete(:format) })) + assert_equal(expected, ResponseBank.cache_key_for(@data.tap { |h| h.delete(:format) })) end def test_cache_key_with_key_and_version version = { version: 42 } expected = %|bar,1,a,b,2,{:baz=>\"buzz\"},{:red=>[\"blue\", \"green\"], :day=>true, :night=>nil, :updated_at=>2011-06-29 15:47:47 UTC, :published_on=>Wed, 29 Jun 2011},text/html:42| # rubocop:disable Metrics/LineLength - assert_equal(expected, Cacheable.cache_key_for(key: @data, version: version)) + assert_equal(expected, ResponseBank.cache_key_for(key: @data, version: version)) end end diff --git a/test/response_cache_handler_test.rb b/test/response_cache_handler_test.rb index 5a1ed62..86a36db 100644 --- a/test/response_cache_handler_test.rb +++ b/test/response_cache_handler_test.rb @@ -7,7 +7,7 @@ class ResponseCacheHandlerTest < Minitest::Test def setup @cache_store = stub.tap { |s| s.stubs(read: nil) } controller.request.env['HTTP_IF_NONE_MATCH'] = 'deadbeefdeadbeef' - Cacheable.stubs(:acquire_lock).returns(true) + ResponseBank.stubs(:acquire_lock).returns(true) end def controller @@ -15,7 +15,7 @@ def controller end def handler - @handler = Cacheable::ResponseCacheHandler.new( + @handler = ResponseBank::ResponseCacheHandler.new( key_data: controller.send(:cache_key_data), version_data: controller.send(:cache_version_data), cache_store: @cache_store, @@ -29,7 +29,7 @@ def handler end def page - [200, "text/html", Cacheable.compress("hi."), 1331765506] + [200, "text/html", ResponseBank.compress("hi."), 1331765506] end def page_serialized @@ -42,7 +42,7 @@ def page_uncompressed def test_cache_miss_block_is_only_called_once_if_it_return_nil called = 0 - my_handler = Cacheable::ResponseCacheHandler.new( + my_handler = ResponseBank::ResponseCacheHandler.new( key_data: controller.send(:cache_key_data), version_data: controller.send(:cache_version_data), cache_store: @cache_store, @@ -94,7 +94,7 @@ def test_server_recent_cache_hit @controller.stubs(:cache_age_tolerance_in_seconds).returns(999999999999) @cache_store.expects(:read).with(handler.unversioned_key_hash).returns(page_serialized) expect_page_rendered(page_uncompressed) - Cacheable.expects(:acquire_lock).with(handler.versioned_key_hash) + ResponseBank.expects(:acquire_lock).with(handler.versioned_key_hash) handler.run! assert_env(false, 'server') end @@ -107,7 +107,7 @@ def test_server_recent_cache_acceptable_but_none_found end def test_nil_timestamp_in_second_lookup_causes_a_cache_miss - Cacheable.stubs(:acquire_lock).returns(false) + ResponseBank.stubs(:acquire_lock).returns(false) @controller.stubs(:cache_age_tolerance_in_seconds).returns(999999999999) @cache_store.expects(:read).with(handler.unversioned_key_hash).returns(MessagePack.dump(page[0..2])) handler.run! @@ -115,7 +115,7 @@ def test_nil_timestamp_in_second_lookup_causes_a_cache_miss end def test_recent_cache_available_but_not_acceptable - Cacheable.stubs(:acquire_lock).returns(false) + ResponseBank.stubs(:acquire_lock).returns(false) @controller.stubs(:cache_age_tolerance_in_seconds).returns(15) @cache_store.expects(:read).with(handler.unversioned_key_hash).returns(page_serialized) _, _, body = handler.run! @@ -147,7 +147,7 @@ def test_double_render_still_renders @controller.stubs(:serve_from_browser_cache) @controller.stubs(:serve_from_cache) @controller.stubs(force_refill_cache?: false) - Cacheable.expects(:acquire_lock).once.returns(true) + ResponseBank.expects(:acquire_lock).once.returns(true) handler.run! handler.run! @@ -171,14 +171,14 @@ def assert_env(miss, store) def expect_page_rendered(page) _status, content_type, body, _timestamp = page - Cacheable.expects(:decompress).returns(body).once + ResponseBank.expects(:decompress).returns(body).once @controller.response.headers.expects(:[]=).with('Content-Type', content_type) end def expect_compressed_page_rendered(page) _status, content_type, _body, _timestamp = page - Cacheable.expects(:decompress).never + ResponseBank.expects(:decompress).never @controller.response.headers.expects(:[]=).with('Content-Type', content_type) @controller.response.headers.expects(:[]=).with('Content-Encoding', "gzip") diff --git a/test/test_helper.rb b/test/test_helper.rb index b278724..e022cec 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,9 +8,9 @@ require 'action_controller/railtie' require 'mocha/minitest' -require 'cacheable' +require 'response_bank' -Cacheable.logger = Class.new { def info(a); end }.new +ResponseBank.logger = Class.new { def info(a); end }.new class MockController < ActionController::Base def self.after_filter(*args); end @@ -56,17 +56,17 @@ def reset_body! end def logger - Cacheable.logger + ResponseBank.logger end - include Cacheable::Controller + include ResponseBank::Controller def cacheable? true end end -class << Cacheable +class << ResponseBank module ScrubGzipTimestamp def compress(*) gzip_content = super @@ -81,4 +81,4 @@ def compress(*) end $LOAD_PATH << File.expand_path('../lib', __FILE__) -require 'cacheable' +require 'response_bank'