From b7ec4e2c54760e3ae1173fc31a1752658f6ecd8c Mon Sep 17 00:00:00 2001 From: Dave Armstrong Date: Wed, 14 Nov 2018 15:50:47 +0000 Subject: [PATCH] Allow node cache to be reset. As each class inherits directly from `node_util`, each class has its own cache of `node`. This removes the per class cache. Additionally a reset has been added that can be called prior to `Environment` allowing the new environment settings to be used. --- CHANGELOG.md | 8 ++++++++ lib/cisco_node_utils/node.rb | 5 +++++ lib/cisco_node_utils/node_util.rb | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9ebb746..0d6924b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog ========= +## [Unreleased] + +### Added + * `reset_instance` method to node. Allows a single instance of nodeutils to reset the environment cache. + +### Removed + * Removed cache in `node_util.node`, which gave every inheriting class it's own cache. + ## [v1.10.0] ### New Cisco Resources diff --git a/lib/cisco_node_utils/node.rb b/lib/cisco_node_utils/node.rb index ae59e11e..b6a5d46d 100644 --- a/lib/cisco_node_utils/node.rb +++ b/lib/cisco_node_utils/node.rb @@ -237,6 +237,11 @@ def self.instance @instance ||= new end + # Allow instance cache to be reset + def self.reset_instance + @instance = nil + end + def initialize @client = Cisco::Client.create @cmd_ref = nil diff --git a/lib/cisco_node_utils/node_util.rb b/lib/cisco_node_utils/node_util.rb index b98ff87d..63bc3b6a 100644 --- a/lib/cisco_node_utils/node_util.rb +++ b/lib/cisco_node_utils/node_util.rb @@ -21,7 +21,7 @@ module Cisco # NodeUtil - generic functionality for node utility subclasses to use class NodeUtil def self.node - @node ||= Cisco::Node.instance + Cisco::Node.instance end def node