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 CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -27,7 +27,7 @@ module CacheBack
27
27
  end
28
28
 
29
29
  def cache_back_key_for(id)
30
- "cache_back/#{name}/version_#{inherited_cache_back_version}/#{id}"
30
+ "cache_back/#{table_name}/version_#{inherited_cache_back_version}/#{id}"
31
31
  end
32
32
 
33
33
  def has_cache_back(options = {})
@@ -1,30 +1,58 @@
1
1
  module CacheBack
2
2
  module WriteMixin
3
- def shallow_clone
4
- clone = self.class.new
5
- clone.instance_variable_set("@attributes", instance_variable_get(:@attributes))
6
- clone.instance_variable_set("@new_record", new_record?)
7
- clone
8
- end
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
- def cache_back_key
11
- @cache_back_key ||= new_record? ? nil : self.class.cache_back_key_for(id)
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
- def store_in_cache_back
15
- if !readonly? && cache_back_key
16
- CacheBack.cache.write(cache_back_key, shallow_clone, self.class.inherited_cache_back_options)
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
- def remove_from_cache_back
21
- CacheBack.cache.delete(cache_back_key) if cache_back_key
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_back
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard