@@ -18,12 +18,20 @@ module Fragments
18
18
# a key suitable for use in reading, writing, or expiring a
19
19
# cached fragment. All keys are prefixed with <tt>views/</tt> and uses
20
20
# ActiveSupport::Cache.expand_cache_key for the expansion.
21
+ #
22
+ # @param [Hash, #cache_key, Array, #to_a, #to_param] key
23
+ # @return [String]
21
24
def fragment_cache_key ( key )
22
25
ActiveSupport ::Cache . expand_cache_key ( key . is_a? ( Hash ) ? url_for ( key ) . split ( "://" ) . last : key , :views )
23
26
end
24
27
25
28
# Writes +content+ to the location signified by
26
29
# +key+ (see +expire_fragment+ for acceptable formats).
30
+ #
31
+ # @param [Hash, #cache_key, Array, #to_a, #to_param] key
32
+ # @param [#to_str] content
33
+ # @param [Hash, nil] options
34
+ # @return [String]
27
35
def write_fragment ( key , content , options = nil )
28
36
return content unless cache_configured?
29
37
@@ -37,6 +45,10 @@ def write_fragment(key, content, options = nil)
37
45
38
46
# Reads a cached fragment from the location signified by +key+
39
47
# (see +expire_fragment+ for acceptable formats).
48
+ #
49
+ # @param [Hash, #cache_key, Array, #to_a, #to_param] key
50
+ # @param [Hash, nil] options
51
+ # @return [String, nil]
40
52
def read_fragment ( key , options = nil )
41
53
return unless cache_configured?
42
54
@@ -49,6 +61,10 @@ def read_fragment(key, options = nil)
49
61
50
62
# Check if a cached fragment from the location signified by
51
63
# +key+ exists (see +expire_fragment+ for acceptable formats).
64
+ #
65
+ # @param [Hash, #cache_key, Array, #to_a, #to_param] key
66
+ # @param [Hash, nil] options
67
+ # @return [Boolean]
52
68
def fragment_exist? ( key , options = nil )
53
69
return unless cache_configured?
54
70
key = fragment_cache_key ( key )
@@ -76,6 +92,10 @@ def fragment_exist?(key, options = nil)
76
92
#
77
93
# +options+ is passed through to the cache store's +delete+
78
94
# method (or <tt>delete_matched</tt>, for Regexp keys).
95
+ #
96
+ # @param [Hash, #cache_key, Array, #to_a, #to_param] key
97
+ # @param [Hash, nil] options
98
+ # @return [void]
79
99
def expire_fragment ( key , options = nil )
80
100
return unless cache_configured?
81
101
key = fragment_cache_key ( key ) unless key . is_a? ( Regexp )
@@ -89,6 +109,9 @@ def expire_fragment(key, options = nil)
89
109
end
90
110
end
91
111
112
+ # @param [#to_s] name
113
+ # @param [Hash, #cache_key, Array, #to_a, #to_param] key
114
+ # @return [void]
92
115
def instrument_fragment_cache ( name , key ) # :nodoc:
93
116
ActiveSupport ::Notifications . instrument ( "#{ name } .action_controller" , :key => key ) { yield }
94
117
end
0 commit comments