Skip to content

Commit 26c04bb

Browse files
committed
Merge pull request #8 from futureworkz/cache-control
TIL Rails: Cache Control in Rails
2 parents 660a171 + c9874e6 commit 26c04bb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rails/cache-control-in-rails.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Cache Control in Rails
2+
3+
Whenever we load a page in browser, it will stores a cached version of the page.
4+
5+
So if users press the back buttons, the browser will simply load the cache version of the page.
6+
7+
This can be an issues when there sensitive information involve.
8+
9+
We can simply set the header `Cache-Control` in our `application_controller.rb`
10+
11+
```ruby
12+
#application_controller
13+
before_filter :set_as_private
14+
15+
protected
16+
17+
def set_as_private
18+
response.headers['Cache-Control'] = 'no-cache, no-store'
19+
end
20+
```
21+
22+
In the case where you only need it in specific page, just use the `before_filter` in respective controller.

0 commit comments

Comments
 (0)