Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 6769e36

Browse files
committed
Added XML file caching to the ConfigurationService.
1 parent 486b296 commit 6769e36

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main/scala/org/codeoverflow/chatoverflow/configuration/ConfigurationService.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class ConfigurationService(val configFilePath: String) extends WithLogger {
2424
<connectorInstances></connectorInstances>
2525
</config>
2626

27+
// Note: Right now, its not supported to reload the framework / load the config more than once. So, caching is easy!
28+
private var cachedXML: Option[Node] = None
29+
2730
/**
2831
* Reads the config xml file and creates plugin instances, saved in the instance registry.
2932
*
@@ -74,17 +77,19 @@ class ConfigurationService(val configFilePath: String) extends WithLogger {
7477
}
7578

7679
/**
77-
* Loads the config xml file and return its content.
80+
* Loads the config xml file and return its content. Supports caching of the xml file.
7881
*/
7982
private def loadXML(): Node = {
80-
if (!new File(configFilePath).exists()) {
81-
logger debug s"Config file '$configFilePath' not found. Initialising with default values."
82-
saveXML(defaultContent)
83-
}
83+
if (cachedXML.isEmpty) {
84+
if (!new File(configFilePath).exists()) {
85+
logger debug s"Config file '$configFilePath' not found. Initialising with default values."
86+
saveXML(defaultContent)
87+
}
8488

85-
val xmlContent = xml.Utility.trim(xml.XML.loadFile(configFilePath))
86-
logger info "Loaded config file."
87-
xmlContent
89+
cachedXML = Some(xml.Utility.trim(xml.XML.loadFile(configFilePath)))
90+
logger info "Loaded config file."
91+
}
92+
cachedXML.get
8893
}
8994

9095
/**

0 commit comments

Comments
 (0)