cached_resource 5.1.3 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 769d5356d807aba4f41cc6be8c2d256921d028b1f205350f0e77024a4db15829
4
- data.tar.gz: 89d9d4bb95b3f325265124bc2d6dd877f68ce0fe6eabe5af2eb9d85327c03ca8
3
+ metadata.gz: 29a5076e42c43b34a6d5b430c8dc16ce062dd3f7f1ac4f63f992efef03b3ccf9
4
+ data.tar.gz: ff819f199885c83cb65a6e21d1a319c5bb6b747dd467870c913043765fbfa111
5
5
  SHA512:
6
- metadata.gz: 6f2574db0f3bd31b1204a361c0c24c9494860947a63e9de90e5dc02762e2d78a034e6e68b380e763af574b2a5d0fc64c3107dbb86644de85fdfe0f8b16ff257c
7
- data.tar.gz: 06c1087d5b036408ef7729e728ad27f8ae59dc2ec954a388fbbe455dc399fcc06b6d69a0bfa9f949c4e86761241a9a15a63d8956c18a1a3d696c4d9669a660d1
6
+ metadata.gz: ea526acccd50610cf5c39248c9c0180c7a6ca1ca42cb6975df9b6f97b668febda6fc17684e9a9a7ca4b371798019d7d5e818e7a34e428702aeb5f475859ddbae
7
+ data.tar.gz: cc087aa9dcc0ad28b8779cf4412fd999b84019b7398d610e2e9e271b14d550bb9baa9dd039a0fa10da6bd15c83f76cba843769723e7bd0ca13a8d3f2f24c0e5e
@@ -24,8 +24,8 @@ module CachedResource
24
24
  end
25
25
 
26
26
  # Clear the cache.
27
- def clear_cache
28
- cache_clear
27
+ def clear_cache(options=nil)
28
+ cache_clear(options)
29
29
  end
30
30
 
31
31
  private
@@ -111,15 +111,26 @@ module CachedResource
111
111
  end
112
112
 
113
113
  # Clear the cache.
114
- def cache_clear
115
- cached_resource.cache.clear.tap do |result|
116
- cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} CLEAR")
114
+ def cache_clear(options=nil)
115
+ # Memcache doesn't support delete_matched, which can also be computationally expensive
116
+ if cached_resource.cache.class.to_s == 'ActiveSupport::Cache::MemCacheStore' || options.try(:fetch,:all)
117
+ cached_resource.cache.clear.tap do |result|
118
+ cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} CLEAR ALL")
119
+ end
120
+ else
121
+ cached_resource.cache.delete_matched("^#{name_key}/*").tap do |result|
122
+ cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} CLEAR #{name_key}/*")
123
+ end
117
124
  end
118
125
  end
119
126
 
120
127
  # Generate the request cache key.
121
128
  def cache_key(*arguments)
122
- "#{name.parameterize.gsub("-", "/")}/#{arguments.join('/')}".downcase.delete(' ')
129
+ "#{name_key}/#{arguments.join('/')}".downcase.delete(' ')
130
+ end
131
+
132
+ def name_key
133
+ name.parameterize.gsub("-", "/")
123
134
  end
124
135
 
125
136
  # Make a full duplicate of an ActiveResource record.
@@ -1,3 +1,3 @@
1
1
  module CachedResource
2
- VERSION = "5.1.3"
2
+ VERSION = "5.2.0"
3
3
  end
@@ -12,6 +12,11 @@ describe CachedResource do
12
12
  cached_resource
13
13
  end
14
14
 
15
+ class NotTheThing < ActiveResource::Base
16
+ self.site = "http://api.notthething.com"
17
+ cached_resource
18
+ end
19
+
15
20
  @thing = {:thing => {:id => 1, :name => "Ada"}}
16
21
  @other_thing = {:thing => {:id => 1, :name => "Ari"}}
17
22
  @thing2 = {:thing => {:id => 2, :name => "Joe"}}
@@ -26,11 +31,15 @@ describe CachedResource do
26
31
  @other_string_thing_json = @other_string_thing.to_json
27
32
  @date_thing_json = @date_thing.to_json
28
33
  @nil_thing = nil.to_json
34
+ @not_the_thing = {:not_the_thing => {:id => 1, :name => "Not"}}
35
+ @not_the_thing_json = @not_the_thing.to_json
29
36
  end
30
37
 
31
38
  after(:each) do
32
39
  Thing.cached_resource.cache.clear
33
40
  Object.send(:remove_const, :Thing)
41
+ NotTheThing.cached_resource.cache.clear
42
+ Object.send(:remove_const, :NotTheThing)
34
43
  end
35
44
 
36
45
  describe "when enabled" do
@@ -39,6 +48,8 @@ describe CachedResource do
39
48
  # to make sure it works
40
49
  Thing.cached_resource.cache.clear
41
50
  Thing.cached_resource.on!
51
+ NotTheThing.cached_resource.cache.clear
52
+ NotTheThing.cached_resource.on!
42
53
 
43
54
  ActiveResource::HttpMock.reset!
44
55
  ActiveResource::HttpMock.respond_to do |mock|
@@ -47,6 +58,7 @@ describe CachedResource do
47
58
  mock.get "/things/fded.json", {}, @string_thing_json
48
59
  mock.get "/things.json?name=42", {}, @nil_thing, 404
49
60
  mock.get "/things/4.json", {}, @date_thing_json
61
+ mock.get "/not_the_things/1.json", {}, @not_the_thing_json
50
62
  end
51
63
  end
52
64
 
@@ -77,6 +89,20 @@ describe CachedResource do
77
89
  read_from_cache("thing/1").should == nil
78
90
  end
79
91
 
92
+ it "should not empty the cache of NotTheThing when clear_cache is called on the Thing" do
93
+ result1 = Thing.find(1)
94
+ result2 = NotTheThing.find(1)
95
+ Thing.clear_cache
96
+ NotTheThing.send(:cache_read, 'notthething/1').should == result2
97
+ end
98
+
99
+ it "should empty all the cache when clear_cache is called on the Thing with :all option set" do
100
+ result1 = Thing.find(1)
101
+ result2 = NotTheThing.find(1)
102
+ Thing.clear_cache(all: true)
103
+ NotTheThing.send(:cache_read, 'notthething/1').should == nil
104
+ end
105
+
80
106
  it "should cache a response with the same persistence" do
81
107
  result1 = Thing.find(1)
82
108
  result1.persisted?.should be true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cached_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.3
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morgan Brown
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-23 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource