manage_cache 0.0.4 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ec215d42d1220af0f9d531d8128392d156f6b88
4
- data.tar.gz: 6491ed7f5dbcc10871c1f4e8c56b6589cb426707
3
+ metadata.gz: d086284c04b727bf43511670bb8e88bc4848e8c1
4
+ data.tar.gz: fefd47861d23256b765a6d4ff9fa07034ea1e833
5
5
  SHA512:
6
- metadata.gz: 54e6a07d3f77d5b76f8e3ceacf14fc8ebbc3dc0865474a490d2ee0e05ac7655e425078715c715fa047489e725644456dfc6ccb8fd824f14ba2473c625408c9bf
7
- data.tar.gz: b566c0381c9c34bc72ec25390aa46dda1c3062f8a8379b7072c3986a385ad41d14694a1cc3a1f29115d1f96f8950945ff8bda41697ac1516f6f69568c7e43dda
6
+ metadata.gz: 4831115ab6e9f5a6331c17a55f656afe9fb08f3b67e310c32698884ac7dfc42adc16c93cb52a05d2f979c97ecb16d310c14b7ec0a54f5cb4f8bdbac50639249e
7
+ data.tar.gz: f377bae3bc05679acd25c5ac3a9d368150a6481a7af0116ff9ab01a183d2296045ba6fc13ca77b6ab23e80ef289a522d930af5fe591c795b92aabc638e5e54a5
@@ -1,3 +1,3 @@
1
1
  module ManageCache
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/manage_cache.rb CHANGED
@@ -23,19 +23,14 @@ module ManageCache
23
23
  module LocalInstanceMethods
24
24
  def dump_cache!
25
25
  self.class.cache_keys_specs.each do |key_name, key_specs|
26
- # the rails helper method 'cache (name, opts) do ...'
27
- # adds some extras to the cache key.
28
- # To run with this gem, you have to add 'skip_digest: true'.
29
- # Any other options will prevent correct cache deletion!!
30
- #
31
- [cache_key_for(key_name), "views/#{cache_key_for(key_name)}"].each do |key|
26
+ if delete_cache?(key_specs)
32
27
  if !key_specs[:regexp].blank?
33
- delete_cache_w_regexp(key, key_specs)
28
+ delete_cache_w_regexp(key_name)
29
+ #delete_cache_w_regexp(key, key_specs)
34
30
  else
35
- Rails.cache.delete(key)
36
31
  end
37
32
  instance_variable_set("@cache_key_for_#{key_name}", nil)
38
- end if delete_cache?(key_specs)
33
+ end
39
34
  end
40
35
  end
41
36
 
@@ -129,11 +124,29 @@ module ManageCache
129
124
  #
130
125
  # be aware, that the matcher_string has to be escaped (e.g. "\\d+" instead of "\d+")!
131
126
  #
132
- def delete_cache_w_regexp(key, specs)
133
- regexp = specs[:regexp].inject([]){|m, (k,v)| m << "#{k}=#{v}" }.join('-')
127
+ def delete_cache_w_regexp(key_name)
128
+ specs = self.class.cache_keys_specs[key_name]
129
+
130
+ regexp = specs[:regexp].inject([]) do |m, (k,v)|
131
+ redis_store = Rails.cache.class == ActiveSupport::Cache::RedisStore
132
+ m << "#{k}=#{redis_store ? '*' : v}"
133
+ end.join('-')
134
+
135
+ key = prepare_cache_key(key_name)
134
136
  Rails.cache.delete_matched("#{Regexp.escape(key)}-#{regexp}")
135
137
  end
136
138
 
139
+ # the rails helper method 'cache (name, opts) do ...'
140
+ # adds some extras to the cache key.
141
+ # To run with this gem, you have to add 'skip_digest: true'.
142
+ # Any other options will prevent correct cache deletion!!
143
+ #
144
+ def delete_cache(key_name)
145
+ [cache_key_for(key_name), "views/#{cache_key_for(key_name)}"].each do |key|
146
+ Rails.cache.delete(key)
147
+ end
148
+ end
149
+
137
150
  # if some attributes are specified in :if_changed
138
151
  # check whether they changed
139
152
  # and delete cache only if they changed
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manage_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - cgregor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-18 00:00:00.000000000 Z
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails