-
Notifications
You must be signed in to change notification settings - Fork 74
RequestStore
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:
Basics
Diving in
- bin/setup
- Config
- CORS
- Endpoints
- Error Handling
- Logging
- Models
- Mediators
- Migrations
- Rake Tasks
- Request IDs
- RequestStore
- Schema
- Serialization
- Testing
- Updating
Guides