Skip to content
Pedro Belo edited this page Jul 13, 2015 · 1 revision

Many will consider this an anti-pattern, but sometimes having request data available globally is just so incredibly helpful.

Things like Request IDs, feature flags or small amounts of per-request cached data are great candidates to be stored with the RequestStore. This means you can generate these only once, even from a middleware – and have them available in Mediators and other parts of your application without having to pass it explicitly from Endpoints.

Needless to say this should only be used as a last resort. Be explicit and pass variables around for as much as you can!

The store is simply a hash that is thread safe and scoped appropriately to the current application request. Write and read values from it like you would from any hash:

Pliny::RequestStore.store[:foo] = 'bar'

Further reading: