moduleLocalCacheRegistryCleanupWithEnsureLocalCacheRegistry=ActiveSupport::Cache::Strategy::LocalCache::LocalCacheRegistryLocalStore=ActiveSupport::Cache::Strategy::LocalCache::LocalStoredefcall(env)LocalCacheRegistry.set_cache_for(local_cache_key,LocalStore.new)response=@app.call(env)response[2]=::Rack::BodyProxy.new(response[2])doLocalCacheRegistry.set_cache_for(local_cache_key,nil)endcleanup_after_response=true# ADDED THIS LINEresponserescueRack::Utils::InvalidParameterError[400,{},[]]ensure# ADDED ensure CLAUSE to cleanup when something is thrownLocalCacheRegistry.set_cache_for(local_cache_key,nil)unlesscleanup_after_responseendendActiveSupport::Cache::Strategy::LocalCache::Middleware.prepend(LocalCacheRegistryCleanupWithEnsure)