Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache statistics #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ In `config/initializers/stat_board.rb`:

StatBoard.display_graph = true

4. Data cache lifetime (1 hour by default)

StatBoard.cache_lifetime = 1.day

## Issues

* Models can be specified as strings rather than constants
Expand Down
13 changes: 7 additions & 6 deletions app/views/stat_board/stats/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<% if StatBoard.models %>
<div class="row">
<%= render :partial => "chart", :collection => @reports, :as => :report %>
</div>
<% cache "stat_board", expires_in: StatBoard.cache_lifetime do %>
<div class="row">
<%= render :partial => "chart", :collection => @reports, :as => :report %>
</div>

<% if StatBoard.display_graph %>
<%= render "graph" %>
<% if StatBoard.display_graph %>
<%= render "graph" %>
<% end %>
<% end %>

<% else %>
Please specify some models by setting <code>StatBoard.models</code>
(in <code>config/initializers/stat_board.rb</code>, for example).
Expand Down
3 changes: 2 additions & 1 deletion lib/stat_board.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
require "stat_board/graph_helper"

module StatBoard
mattr_accessor :models, :title, :display_graph, :username, :password
mattr_accessor :models, :title, :display_graph, :username, :password, :cache_lifetime

# Display graph by default. Can be disabled in initializers/stat_board.rb.
@@display_graph = true
@@cache_lifetime = 1.hour
end