From 9bb314cb170a651571b57767d33b3c01112aa5bc Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 17 Feb 2025 00:26:07 +0200 Subject: cache the resource objs --- lib/dslkeywords/resource.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/dslkeywords/resource.rb b/lib/dslkeywords/resource.rb index 11df70e..f646030 100644 --- a/lib/dslkeywords/resource.rb +++ b/lib/dslkeywords/resource.rb @@ -69,12 +69,16 @@ module RCM class NoSuchResourceObject < StandardError; end + @@resource_find_cache = {} + def self.find(id) + return @@resource_find_cache[id] if @@resource_find_cache.key?(id) + klass = Object.const_get("RCM::#{id.split('(').first.capitalize}") resource = ObjectSpace.each_object(klass).find { _1.id == id } raise NoSuchResourceObject, "Unable to find resource #{id}" if resource.nil? - resource + @@resource_find_cache[id] = resource end end end -- cgit v1.2.3