diff options
author | Rémy Coutable <remy@rymai.me> | 2017-03-13 10:15:56 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-03-13 10:15:56 +0000 |
commit | f49868adf1a2ea24815d432640cd0d996e0d87a0 (patch) | |
tree | d0671c5253e7e666d9b690ed3872f543202e99a4 | |
parent | 31b6ca50c36c5e5e990633105ca5dcefb5e6f369 (diff) | |
parent | 22ff9b78aef7356f36d259d8b0a05d7d02565c9a (diff) | |
download | gitlab-ce-f49868adf1a2ea24815d432640cd0d996e0d87a0.tar.gz |
Merge branch 'backport-cache-middleware-fix' into 'master'
Backport cache middleware fix
See merge request !9867
-rw-r--r-- | config/initializers/fix_local_cache_middleware.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/config/initializers/fix_local_cache_middleware.rb b/config/initializers/fix_local_cache_middleware.rb new file mode 100644 index 00000000000..cb37f9ed22c --- /dev/null +++ b/config/initializers/fix_local_cache_middleware.rb @@ -0,0 +1,24 @@ +module LocalCacheRegistryCleanupWithEnsure + LocalCacheRegistry = + ActiveSupport::Cache::Strategy::LocalCache::LocalCacheRegistry + LocalStore = + ActiveSupport::Cache::Strategy::LocalCache::LocalStore + + def call(env) + LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new) + response = @app.call(env) + response[2] = ::Rack::BodyProxy.new(response[2]) do + LocalCacheRegistry.set_cache_for(local_cache_key, nil) + end + cleanup_after_response = true # ADDED THIS LINE + response + rescue Rack::Utils::InvalidParameterError + [400, {}, []] + ensure # ADDED ensure CLAUSE to cleanup when something is thrown + LocalCacheRegistry.set_cache_for(local_cache_key, nil) unless + cleanup_after_response + end +end + +ActiveSupport::Cache::Strategy::LocalCache::Middleware + .prepend(LocalCacheRegistryCleanupWithEnsure) |