Skip to content

Commit 985767a

Browse files
authored
Merge pull request rails#44 from biow0lf/colorize-examples-in-readme-md
Colorize examples in README.md [ci skip]
2 parents d73dd50 + 160f812 commit 985767a

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

README.md

+34-28
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Installation
88

99
Add this line to your application's Gemfile:
1010

11-
gem "actionpack-action_caching"
11+
```ruby
12+
gem 'actionpack-action_caching'
13+
```
1214

1315
And then execute:
1416

@@ -28,12 +30,14 @@ that filters run before the cache is served, which allows for
2830
authentication and other restrictions on whether someone is allowed
2931
to execute such action.
3032

31-
class ListsController < ApplicationController
32-
before_action :authenticate, except: :public
33+
```ruby
34+
class ListsController < ApplicationController
35+
before_action :authenticate, except: :public
3336

34-
caches_page :public
35-
caches_action :index, :show
36-
end
37+
caches_page :public
38+
caches_action :index, :show
39+
end
40+
```
3741

3842
In this example, the `public` action doesn't require authentication
3943
so it's possible to use the faster page caching. On the other hand
@@ -72,36 +76,38 @@ interval (in seconds) to schedule expiration of the cached item.
7276

7377
The following example depicts some of the points made above:
7478

75-
class ListsController < ApplicationController
76-
before_action :authenticate, except: :public
79+
```ruby
80+
class ListsController < ApplicationController
81+
before_action :authenticate, except: :public
7782

78-
# simple fragment cache
79-
caches_action :current
83+
# simple fragment cache
84+
caches_action :current
8085

81-
# expire cache after an hour
82-
caches_action :archived, expires_in: 1.hour
86+
# expire cache after an hour
87+
caches_action :archived, expires_in: 1.hour
8388

84-
# cache unless it's a JSON request
85-
caches_action :index, unless: -> { request.format.json? }
89+
# cache unless it's a JSON request
90+
caches_action :index, unless: -> { request.format.json? }
8691

87-
# custom cache path
88-
caches_action :show, cache_path: { project: 1 }
92+
# custom cache path
93+
caches_action :show, cache_path: { project: 1 }
8994

90-
# custom cache path with a proc
91-
caches_action :history, cache_path: -> { request.domain }
95+
# custom cache path with a proc
96+
caches_action :history, cache_path: -> { request.domain }
9297

93-
# custom cache path with a symbol
94-
caches_action :feed, cache_path: :user_cache_path
98+
# custom cache path with a symbol
99+
caches_action :feed, cache_path: :user_cache_path
95100

96-
protected
97-
def user_cache_path
98-
if params[:user_id]
99-
user_list_url(params[:user_id], params[:id])
100-
else
101-
list_url(params[:id])
102-
end
103-
end
101+
protected
102+
def user_cache_path
103+
if params[:user_id]
104+
user_list_url(params[:user_id], params[:id])
105+
else
106+
list_url(params[:id])
107+
end
104108
end
109+
end
110+
```
105111

106112
If you pass `layout: false`, it will only cache your action
107113
content. That's useful when your layout has dynamic information.

0 commit comments

Comments
 (0)