Permalink
Browse files

announcing requeststore

  • Loading branch information...
1 parent 84254a0 commit 2bb268c073abcb3c1163912544ca4a4a8b4d4ee8 @steveklabnik committed Dec 17, 2012
Showing with 37 additions and 0 deletions.
  1. +37 −0 posts/2012-12-17-announcing-requeststore.md
View
37 posts/2012-12-17-announcing-requeststore.md
@@ -0,0 +1,37 @@
+---
+title: "Announcing RequestStore"
+date: 2012-12-17 12:55
+---
+
+Last night I had some insomnia, so I wrote a gem.
+
+Here it is: [https://github.com/steveklabnik/request_store](https://github.com/steveklabnik/request_store).
+
+TL;DR:
+
+If you're using `Thread.current` in your Rails app to store global-ish data,
+don't do it! If you use Thin or Puma or a threaded web server, it won't get
+reset between requests, and you'll end up with subtle bugs. So do this instead:
+
+```
+gem "request_store"
+```
+
+and replace
+
+```
+Thread.current[:foo] = 1
+```
+
+with
+
+```
+RequestStore.store[:foo] = 1
+```
+
+And things will be peachy keen.
+
+### No Rails?
+
+If you're not using Rails, `use RequestStore::Middleware` to make it work. If
+you are using Rails, a Railtie takes care of it for you.

0 comments on commit 2bb268c

Please sign in to comment.