model-cache 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/model_cache.rb +27 -13
  2. metadata +2 -2
data/lib/model_cache.rb CHANGED
@@ -10,30 +10,44 @@ module ModelCache
10
10
  def cache(key, time = DEFAULT_TIME, &block)
11
11
  ModelCache::cache([self.cache_key, key], time, &block)
12
12
  end
13
-
13
+
14
14
  def self.cache(ckey, time = DEFAULT_TIME, &block)
15
15
  cache_hit = false
16
16
  if Rails.configuration.action_controller.perform_caching
17
- result = CACHE.get(ckey) rescue nil
18
- if result
19
- cache_hit = true
20
- end
21
- if result == NIL_OBJECT
22
- nil
17
+ if CACHE.class.name == 'Memcached'
18
+ begin
19
+ result = CACHE.get(ckey.hash.to_s)
20
+ cache_hit = true
21
+ rescue Memcached::NotFound => e
22
+ end
23
+ elsif CACHE.class.name == 'MemCache'
24
+ result = CACHE.get(ckey.hash.to_s)
25
+ if result
26
+ cache_hit = true
27
+ end
28
+ if result == NIL_OBJECT
29
+ nil
30
+ else
31
+ result
32
+ end
23
33
  else
24
- result
34
+ raise "CACHE object not configured #{CACHE.inspect}!"
25
35
  end
26
36
  end
27
37
  unless cache_hit
28
38
  result = block.call
29
- if Rails.configuration.action_controller.perform_caching
30
- begin
39
+ if Rails.configuration.action_controller.perform_caching
40
+ if CACHE.class.name == 'MemCache'
31
41
  if result
32
- CACHE.set(ckey, result, time)
42
+ CACHE.set(ckey.hash.to_s, result, time)
33
43
  else
34
- CACHE.set(ckey, NIL_OBJECT, time)
44
+ CACHE.set(ckey.hash.to_s, NIL_OBJECT, time)
35
45
  end
36
- end rescue nil
46
+ elsif CACHE.class.name == 'Memcached'
47
+ CACHE.set(ckey.hash.to_s, result, time)
48
+ else
49
+ raise "CACHE object not configured #{CACHE.inspect}!"
50
+ end
37
51
  end
38
52
  result
39
53
  end
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.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frantisek Havluj
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-19 00:00:00 +01:00
12
+ date: 2010-01-22 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15