Skip to content

Commit

Permalink
added docs for Base.cache :if.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Aug 15, 2011
1 parent 30aff37 commit fc28a16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.textile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ h2. 3.6.5
h3. Bugfixes
* `Cell::TestCase#invoke` now properly accepts state-args.

h3. Changes
* Added the `:if` option to `Base.cache` which allows adding a conditional proc or instance method to the cache definition. If it doesn't return true, caching for that state is skipped.


h2. 3.6.4

Expand Down
9 changes: 7 additions & 2 deletions lib/cell/caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ module ClassMethods
#
# cache :show, :expires_in => 10.minutes
#
# The +:if+ option lets you define a conditional proc or instance method. If it doesn't
# return a true value, caching for that state is skipped.
#
# cache :show, :if => proc { |cell, options| options[:enable_cache] }
#
# If you need your own granular cache keys, pass a versioner block.
#
# cache :show do |cell, options|
Expand Down Expand Up @@ -112,12 +117,12 @@ def call_proc_or_method(state, method, *args)

def call_state_versioner(state, *args)
method = self.class.version_procs[state] or return
call_proc_or_method state, method, *args
call_proc_or_method(state, method, *args)
end

def call_state_conditional(state, *args)
method = self.class.conditional_procs[state] or return true
call_proc_or_method state, method, *args
call_proc_or_method(state, method, *args)
end

end
Expand Down

0 comments on commit fc28a16

Please sign in to comment.