Skip to content

Commit

Permalink
Add a cache around the check loader
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Sep 12, 2023
1 parent 00b143d commit 9e3ab40
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions shaperglot/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

definitions_directory = Path(__file__).parent / "languages"

definition_cache = {}

def load_shaperglot_definition(language, validate=False):
if language in definition_cache:
return definition_cache[language]
definition_file = definitions_directory / (language + ".yaml")
if not definition_file.is_file():
return []
Expand All @@ -40,6 +43,7 @@ def load_shaperglot_definition(language, validate=False):
) from e
# This turns a { "check": "foobar" } into a FoobarCheck({"check": "foobar"})
check_objects.append(checks_map[check["check"]](check))
definition_cache[language] = check_objects
return check_objects


Expand Down

0 comments on commit 9e3ab40

Please sign in to comment.