Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactor

  • Loading branch information...
commit 1840aed131b35a7f3c2861c2c1ba05a115f0a8e1 1 parent a610ed9
Dejan Simic authored July 19, 2011

Showing 1 changed file with 18 additions and 5 deletions. Show diff stats Hide diff stats

  1. 23  lib/will_cache/cacheable.rb
23  lib/will_cache/cacheable.rb
... ...
@@ -1,8 +1,13 @@
1 1
 module WillCache
2 2
   module Cacheable
  3
+
  4
+    def cache
  5
+      Rails.cache
  6
+    end
  7
+
3 8
     def expire_cache(method_name = nil, args = {})
4 9
       with = args[:with]
5  
-      Rails.cache.delete(method_cache_key(method_name, with))
  10
+      cache.delete(method_cache_key(method_name, with))
6 11
       true
7 12
     end
8 13
 
@@ -12,16 +17,24 @@ def cached(method_name, args = {})
12 17
       # Rails.fetch is broken
13 18
       # http://developingsimplicity.com/posts/rails-cache-fetch
14 19
       key = method_cache_key(method_name, with)
15  
-      if Rails.cache.exist?(key)
16  
-        Rails.cache.read(key)
  20
+      if cache.exist?(key)
  21
+        cache.read(key)
17 22
       else
18  
-        Rails.cache.write(key, do_send(method_name, with))
  23
+        cache.write(key, do_send(method_name, with))
19 24
       end
20 25
     end
21 26
 
22 27
     def fetch_cache(method_name, args = {})
23 28
       with = args[:with]
24  
-      Rails.cache.read(method_cache_key(method_name, with))
  29
+      cache.read(method_cache_key(method_name, with))
  30
+    end
  31
+
  32
+    def write_cache(key, value, ttl = nil)
  33
+      cache.write(key, value, :expires_in => ttl)
  34
+    end
  35
+
  36
+    def read_cache(key)
  37
+      cache.read(key)
25 38
     end
26 39
 
27 40
     def do_send(method_name, with)

0 notes on commit 1840aed

Please sign in to comment.
Something went wrong with that request. Please try again.