will_cache 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/will_cache/cacheable.rb +17 -8
- metadata +3 -3
data/lib/will_cache/cacheable.rb
CHANGED
@@ -3,8 +3,7 @@ module WillCache
|
|
3
3
|
|
4
4
|
def expire_cache(method_name = nil, args = {})
|
5
5
|
with = args[:with]
|
6
|
-
|
7
|
-
true
|
6
|
+
delete_cache(method_cache_key(method_name, with))
|
8
7
|
end
|
9
8
|
alias :clear_cache :expire_cache
|
10
9
|
|
@@ -14,27 +13,37 @@ module WillCache
|
|
14
13
|
# Rails.fetch is broken
|
15
14
|
# http://developingsimplicity.com/posts/rails-cache-fetch
|
16
15
|
key = method_cache_key(method_name, with)
|
17
|
-
if
|
18
|
-
|
16
|
+
if cache_exist?(key)
|
17
|
+
read_cache(key)
|
19
18
|
else
|
20
|
-
|
19
|
+
write_cache(key, do_send(method_name, with))
|
21
20
|
end
|
22
21
|
end
|
23
22
|
alias :caches :cached
|
24
23
|
|
25
24
|
def fetch_cache(method_name, args = {})
|
26
25
|
with = args[:with]
|
27
|
-
|
26
|
+
read_cache(method_cache_key(method_name, with))
|
28
27
|
end
|
29
28
|
|
30
|
-
def write_cache(key, value
|
31
|
-
Rails.cache.write(key, value
|
29
|
+
def write_cache(key, value)
|
30
|
+
Rails.cache.write(key, value)
|
31
|
+
value
|
32
32
|
end
|
33
33
|
|
34
34
|
def read_cache(key)
|
35
35
|
Rails.cache.read(key)
|
36
36
|
end
|
37
37
|
|
38
|
+
def delete_cache(key)
|
39
|
+
Rails.cache.delete(key)
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def cache_exist?(key)
|
44
|
+
Rails.cache.exist?(key)
|
45
|
+
end
|
46
|
+
|
38
47
|
def do_send(method_name, with)
|
39
48
|
if with.blank?
|
40
49
|
send(method_name)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dejan Simic
|