model-cache 0.1.4 → 0.1.5

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 (3) hide show
  1. data/README.textile +17 -3
  2. data/lib/model_cache.rb +8 -2
  3. metadata +2 -2
data/README.textile CHANGED
@@ -1,13 +1,27 @@
1
1
  h1. ModelCache
2
2
 
3
- ModelCache is a simple caching plugin for Rails, using memcached. It provides caching abilities for your models, allowing to:
4
- * cache blocks of code in your model instance methods, based on a generic key (ActiveRecord cache_key is added behind the scenes)
3
+ ModelCache is a simple caching plugin for Rails, using @memcached@. It provides caching abilities for your models, allowing to:
4
+ * cache blocks of code in your model instance methods, based on a generic key (ActiveRecord @cache_key@ is added behind the scenes)
5
5
  * cache your instance methods, optionally with a time-to-live setting
6
6
  * cache some generic code (e.g. in your class methods)
7
7
 
8
+ h1. Installation
9
+
10
+ p. As a gem:
11
+
12
+ bc. gem install model-cache
13
+
14
+ p. As a plugin:
15
+
16
+ bc. script/plugin install git://github.com/moskyt/model_cache.git
17
+
18
+ or
19
+
20
+ bc. script/plugin install http://github.com/moskyt/model_cache.git
21
+
8
22
  h1. Example
9
23
 
10
- p. environment.rb:
24
+ p. @environment.rb@ or an initializer:
11
25
 
12
26
  bc. require 'memcache'
13
27
  CACHE = MemCache.new('127.0.0.1')
data/lib/model_cache.rb CHANGED
@@ -12,13 +12,19 @@ module ModelCache
12
12
  end
13
13
 
14
14
  def self.cache(ckey, time = DEFAULT_TIME, &block)
15
- if Rails.configuration.action_controller.perform_caching && (result = CACHE.get(ckey))
15
+ cache_hit = false
16
+ if Rails.configuration.action_controller.perform_caching
17
+ result = CACHE.get(ckey) rescue nil
18
+ if result
19
+ cache_hit = true
20
+ end
16
21
  if result == NIL_OBJECT
17
22
  nil
18
23
  else
19
24
  result
20
25
  end
21
- else
26
+ end
27
+ unless cache_hit
22
28
  result = block.call
23
29
  if Rails.configuration.action_controller.perform_caching
24
30
  if result
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.4
4
+ version: 0.1.5
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-12 00:00:00 +01:00
12
+ date: 2010-01-19 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15