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.
Files changed (2) hide show
  1. data/lib/model_cache.rb +6 -7
  2. 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 DO_CACHE && (result = CACHE.get(ckey))
17
- if result == NIL_OBJECT
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 DO_CACHE
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, NIL_OBJECT, time)
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
- !!( DO_CACHE && CACHE.get(ckey) )
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]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frantisek Havluj