Skip to content

Commit 8239f36

Browse files
committed
Add OpenapiFirst.clear_cache! as public interface
1 parent e0cb9a7 commit 8239f36

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
## Unreleased
44

5-
- `OpenapiFirst::FileLoader` will now cache the contents of files that have been loaded. This cache
6-
is keyed on the file's path. If you need to reload your OpenAPI definition for tests or server hot
7-
reloading, you can run `OpenapiFirst::FileLoader.clear_cache!`.
5+
- OpenapiFirst will now cache the contents of files that have been loaded. If you need to reload your OpenAPI definition for tests or server hot reloading, you can call `OpenapiFirst.clear_cache!`.
86

97
## 3.2.1
108

lib/openapi_first.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ module OpenapiFirst
2222

2323
FAILURE = :openapi_first_validation_failure
2424

25+
# Clears cached files
26+
def self.clear_cache!
27+
FileLoader.clear_cache!
28+
end
29+
30+
2531
# @return [Configuration]
2632
def self.configuration
2733
@configuration ||= Configuration.new

spec/openapi_first_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
end
5353
end
5454

55+
describe '.clear_cache!' do
56+
it 'clears the file cache so files are reloaded on next load' do
57+
first = OpenapiFirst.load(spec_path)
58+
OpenapiFirst.clear_cache!
59+
second = OpenapiFirst.load(spec_path)
60+
expect(second).not_to be(first)
61+
end
62+
end
63+
5564
describe '.load' do
5665
begin
5766
require 'multi_json'

0 commit comments

Comments
 (0)