Skip to content

Commit cbd6ea9

Browse files
committed
VPN: IPsec: Security Policy Database - extend ModelRelationField so it can optionally disable caching. closes #9365
In some cases caching can be problematic, for example when rows are dynamically generated or when the cache is persisted while the model hasn't reached it final state yet. The latter seems to be the case here. When referring connection, we actually mean the description of the related field, which may not be persisted in the model yet as an earlier field triggered the data to be stored (locals.local.connection for example). This commit adds "DisableCache" as ModelRelationField option and uses it in SPDs.SPD.connection_child
1 parent 3ba41cc commit cbd6ea9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class ModelRelationField extends BaseListField
5151
*/
5252
private $internalOptionsFromThisModel = false;
5353

54+
private $internalDisableCache = false;
55+
5456
/**
5557
* @var string cache relations
5658
*/
@@ -76,7 +78,7 @@ public function getCachedData($classname, $path, $force = false)
7678
if (!class_exists($classname)) {
7779
return []; /* not found */
7880
}
79-
if (!isset(self::$internalCacheModelStruct[$classname]) || $force) {
81+
if ($this->internalDisableCache || !isset(self::$internalCacheModelStruct[$classname]) || $force) {
8082
$pmodel = $this->getParentModel();
8183
if ($pmodel !== null && strcasecmp(get_class($pmodel), $classname) === 0) {
8284
// model options from the same model, use this model instead of creating something new
@@ -165,6 +167,20 @@ public function setModel($mdlStructure)
165167
}
166168
}
167169

170+
/**
171+
* Disable caching and force a model reload, this can be useful in cases where multiple layers of generated
172+
* fields stack on each other which are dependent or if the related model has dynamically generated items.
173+
* (in which case the persisted_at attribute doesn't tell the full story)
174+
*
175+
* @param $value boolean value Y/N
176+
*/
177+
public function setDisableCache($value)
178+
{
179+
$this->internalDisableCache = trim(strtoupper($value)) == "Y";
180+
}
181+
182+
183+
168184
/**
169185
* load model options when initialized
170186
*/

src/opnsense/mvc/app/models/OPNsense/IPsec/Swanctl.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@
418418
<MaximumValue>65535</MaximumValue>
419419
</reqid>
420420
<connection_child type="ModelRelationField">
421+
<DisableCache>Y</DisableCache>
421422
<Model>
422423
<host>
423424
<source>OPNsense.IPsec.Swanctl</source>

0 commit comments

Comments
 (0)