Skip to content

Commit

Permalink
document how to ignore selected middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
ccyrille committed Nov 21, 2019
1 parent ad78267 commit 12594a0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class NonThreadSafeMiddleware
@app = app
@state = 0
end

def call(env)
@state += 1

return @app.call(env)
end
end
Expand All @@ -69,16 +69,16 @@ class CacheEverythingForever
@app = app
@cache_all_the_things = Concurrent::Map.new
end

def freeze
return self if frozen?

# Don't freeze @cache_all_the_things
@app.freeze

super
end

def call(env)
# Use the thread-safe `Concurrent::Map` to fetch the value or store it if it doesn't exist already.
@cache_all_the_things.fetch_or_store(env[Rack::PATH_INFO]) do
Expand All @@ -88,6 +88,16 @@ class CacheEverythingForever
end
```

### Can I ignore a specific middleware ?

In some particular cases, we want to be able to ignore a mutable middleware. This can be done in `config.ru` :

```ruby
Rack::Freeze.configure do |config|
config.ignored_middlewares << MutableButFineMiddleware
end
```

## Contributing

1. Fork it
Expand Down

0 comments on commit 12594a0

Please sign in to comment.