|
Revision 9032, 2.3 kB
(checked in by david, 7 months ago)
|
Fixed that cache fetch method would cause nil exception when called with no options (closes #11253) [remy]
|
| Line | |
|---|
| 1 |
require 'fileutils' |
|---|
| 2 |
require 'uri' |
|---|
| 3 |
require 'set' |
|---|
| 4 |
|
|---|
| 5 |
require 'action_controller/caching/pages' |
|---|
| 6 |
require 'action_controller/caching/actions' |
|---|
| 7 |
require 'action_controller/caching/sql_cache' |
|---|
| 8 |
require 'action_controller/caching/sweeping' |
|---|
| 9 |
require 'action_controller/caching/fragments' |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
module ActionController |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
module Caching |
|---|
| 33 |
def self.included(base) |
|---|
| 34 |
base.class_eval do |
|---|
| 35 |
@@cache_store = nil |
|---|
| 36 |
cattr_reader :cache_store |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
def self.cache_store=(store_option) |
|---|
| 40 |
@@cache_store = ActiveSupport::Cache.lookup_store(store_option) |
|---|
| 41 |
end |
|---|
| 42 |
|
|---|
| 43 |
include Pages, Actions, Fragments |
|---|
| 44 |
include Sweeping, SqlCache if defined?(ActiveRecord) |
|---|
| 45 |
|
|---|
| 46 |
@@perform_caching = true |
|---|
| 47 |
cattr_accessor :perform_caching |
|---|
| 48 |
|
|---|
| 49 |
def self.cache_configured? |
|---|
| 50 |
perform_caching && cache_store |
|---|
| 51 |
end |
|---|
| 52 |
end |
|---|
| 53 |
end |
|---|
| 54 |
|
|---|
| 55 |
protected |
|---|
| 56 |
|
|---|
| 57 |
def cache(key, options = {}, &block) |
|---|
| 58 |
if cache_configured? |
|---|
| 59 |
cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block) |
|---|
| 60 |
else |
|---|
| 61 |
yield |
|---|
| 62 |
end |
|---|
| 63 |
end |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
private |
|---|
| 67 |
def cache_configured? |
|---|
| 68 |
self.class.cache_configured? |
|---|
| 69 |
end |
|---|
| 70 |
end |
|---|
| 71 |
end |
|---|