model-cache 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/model_cache.rb +6 -7
- metadata +1 -1
data/lib/model_cache.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module ModelCache
|
2
2
|
|
3
|
-
DO_CACHE = Rails.configuration.action_controller.perform_caching
|
4
|
-
NIL_OBJECT = :this_is_my_nil_and_not_a_bill
|
5
3
|
DEFAULT_TIME = 12.hours
|
4
|
+
@@nil_object ||= Object.new
|
6
5
|
|
7
6
|
def self.included(klass)
|
8
7
|
klass.extend ClassMethods
|
@@ -13,19 +12,19 @@ module ModelCache
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def self.cache(ckey, time = DEFAULT_TIME, &block)
|
16
|
-
if
|
17
|
-
if result ==
|
15
|
+
if Rails.configuration.action_controller.perform_caching && (result = CACHE.get(ckey))
|
16
|
+
if result == @@nil_object
|
18
17
|
nil
|
19
18
|
else
|
20
19
|
result
|
21
20
|
end
|
22
21
|
else
|
23
22
|
result = block.call
|
24
|
-
if
|
23
|
+
if Rails.configuration.action_controller.perform_caching
|
25
24
|
if result
|
26
25
|
CACHE.set(ckey, result, time)
|
27
26
|
else
|
28
|
-
CACHE.set(ckey,
|
27
|
+
CACHE.set(ckey, @@nil_object, time)
|
29
28
|
end
|
30
29
|
end
|
31
30
|
result
|
@@ -50,7 +49,7 @@ module ModelCache
|
|
50
49
|
end
|
51
50
|
define_method :"__is_cached_#{sym}?" do |*args|
|
52
51
|
ckey = [self.cache_key, sym, *args]
|
53
|
-
!!(
|
52
|
+
!!( Rails.configuration.action_controller.perform_caching && CACHE.get(ckey) )
|
54
53
|
end
|
55
54
|
define_method :"__uncache_#{sym}" do |*args|
|
56
55
|
ckey = [self.cache_key, sym, *args]
|