Skip to content

Commit 1fe6658

Browse files
committed
fix rails cache usage in request federation to use UI cache, while keeping tests running
1 parent ba4e729 commit 1fe6658

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/ontologies_api_client/request_federation.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
require 'active_support/core_ext/hash'
2-
require 'active_support/cache'
32

43
module LinkedData
54
module Client
65
module RequestFederation
76

8-
CACHE = ActiveSupport::Cache::MemoryStore.new
9-
107
def self.included(base)
118
base.extend(ClassMethods)
129
end
@@ -20,8 +17,8 @@ def federated_get(params = {}, &link)
2017
portal_name = portal_name_from_id(conn.url_prefix.to_s)
2118
portal_status = true
2219

23-
unless CACHE.read("federation_portal_up_#{portal_name}").nil?
24-
portal_status = CACHE.read("federation_portal_up_#{portal_name}")
20+
unless Rails.cache.read("federation_portal_up_#{portal_name}").nil?
21+
portal_status = Rails.cache.read("federation_portal_up_#{portal_name}")
2522
end
2623

2724
unless portal_status
@@ -32,7 +29,7 @@ def federated_get(params = {}, &link)
3229
begin
3330
HTTP.get(link.call(conn.url_prefix.to_s.chomp('/')), params, connection: conn)
3431
rescue Exception => e
35-
CACHE.write("federation_portal_up_#{portal_name}", false, expires_in: 10.minutes)
32+
Rails.cache.write("federation_portal_up_#{portal_name}", false, expires_in: 10.minutes)
3633
[OpenStruct.new(errors: "Problem retrieving #{link.call(conn.url_prefix.to_s.chomp('/')) || conn.url_prefix}")]
3734
end
3835
end

test/test_case.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
WebMock.allow_net_connect!
1111

1212
Logger = ::Logger unless defined?(Logger)
13-
CACHE = ActiveSupport::Cache::MemoryStore.new
13+
module Rails
14+
def self.cache
15+
@cache ||= ActiveSupport::Cache::MemoryStore.new
16+
end
17+
end
1418

1519
module LinkedData
1620
module Client

0 commit comments

Comments
 (0)