Skip to content

Commit

Permalink
Merge pull request #635 from tygriffin/fix-cache-key
Browse files Browse the repository at this point in the history
Fix cache key
  • Loading branch information
pozorvlak committed Jan 15, 2015
2 parents a510489 + 36ac0b7 commit 181c36c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Expand Up @@ -57,7 +57,7 @@ def create

respond_to do |format|
if @comment.save
format.html { redirect_to @comment.post, notice: 'Comment was successfully created.' }
format.html { redirect_to @comment.post, notice: "Comment was successfully created." }
format.json { render json: @comment, status: :created, location: @comment }
else
format.html { render action: "new" }
Expand Down
5 changes: 3 additions & 2 deletions app/helpers/application_helper.rb
Expand Up @@ -24,10 +24,11 @@ def forex_link(price)
:target => "_blank"
end

def cache_key_for(klass)
# Produces a cache key for uniquely identifying cached fragments.
def cache_key_for(klass, identifier="all")
count = klass.count
max_updated_at = klass.maximum(:updated_at).try(:utc).try(:to_s, :number)
"#{klass.name.downcase.pluralize}/all-#{count}-#{max_updated_at}"
"#{klass.name.downcase.pluralize}/#{identifier}-#{count}-#{max_updated_at}"
end

end
Expand Down
4 changes: 2 additions & 2 deletions app/views/home/_crops.html.haml
@@ -1,6 +1,6 @@
.row
.col-md-6.hidden-xs
- cache cache_key_for(Crop), :expires_in => 1.day do
- cache cache_key_for(Crop, 'interesting'), :expires_in => 1.day do
%h2= t('.our_crops')
- Crop.interesting.each do |c|
.col-md-3{:style => 'margin:0px; padding: 3px'}
Expand All @@ -13,7 +13,7 @@

.row
.col-md-12
- cache cache_key_for(Crop) do
- cache cache_key_for(Crop, 'recent') do
%p{ :style => 'margin-top: 11.25px' }
%strong
#{t('.recently_added')}:
Expand Down

0 comments on commit 181c36c

Please sign in to comment.