cache_back 0.3.3 → 0.3.4
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.
- data/VERSION +1 -1
- data/lib/cache_back/configuration_mixin.rb +1 -1
- data/lib/cache_back/write_mixin.rb +42 -14
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
@@ -1,30 +1,58 @@
|
|
1
1
|
module CacheBack
|
2
2
|
module WriteMixin
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module ClassMethods
|
4
|
+
def remove_from_cache_back(ids)
|
5
|
+
Array(ids).each do |id|
|
6
|
+
CacheBack.cache.delete(cache_back_key_for(id))
|
7
|
+
end
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
def update_counters_with_cache_back_clearing(*args)
|
11
|
+
remove_from_cache_back(args[0])
|
12
|
+
update_counters_without_cache_back_clearing(*args)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
module InstanceMethods
|
17
|
+
def shallow_clone
|
18
|
+
clone = self.class.new
|
19
|
+
clone.instance_variable_set("@attributes", instance_variable_get(:@attributes))
|
20
|
+
clone.instance_variable_set("@new_record", new_record?)
|
21
|
+
clone
|
22
|
+
end
|
23
|
+
|
24
|
+
def cache_back_key
|
25
|
+
@cache_back_key ||= new_record? ? nil : self.class.cache_back_key_for(id)
|
26
|
+
end
|
27
|
+
|
28
|
+
def store_in_cache_back
|
29
|
+
if !readonly? && cache_back_key
|
30
|
+
CacheBack.cache.write(cache_back_key, shallow_clone, self.class.inherited_cache_back_options)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove_from_cache_back
|
35
|
+
CacheBack.cache.delete(cache_back_key) if cache_back_key
|
17
36
|
end
|
18
|
-
end
|
19
37
|
|
20
|
-
|
21
|
-
|
38
|
+
def reload_with_cache_back_clearing(*args)
|
39
|
+
remove_from_cache_back
|
40
|
+
reload_without_cache_back_clearing(*args)
|
41
|
+
end
|
22
42
|
end
|
23
43
|
|
24
44
|
def self.included(model_class)
|
45
|
+
model_class.extend ClassMethods
|
46
|
+
model_class.send :include, InstanceMethods
|
47
|
+
|
25
48
|
#model_class.after_save :store_in_cache_back
|
26
49
|
model_class.after_update :remove_from_cache_back
|
27
50
|
model_class.after_destroy :remove_from_cache_back
|
51
|
+
model_class.alias_method_chain :reload, :cache_back_clearing
|
52
|
+
|
53
|
+
class << model_class
|
54
|
+
alias_method_chain :update_counters, :cache_back_clearing
|
55
|
+
end
|
28
56
|
end
|
29
57
|
end
|
30
58
|
end
|