From 285abe7cc099d714176da5ce20eb01121b81977d Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 22 Oct 2025 11:22:53 -0700 Subject: [PATCH] 20660 cache script storage key --- netbox/extras/models/mixins.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/netbox/extras/models/mixins.py b/netbox/extras/models/mixins.py index d0422098244..8d3d4b8838f 100644 --- a/netbox/extras/models/mixins.py +++ b/netbox/extras/models/mixins.py @@ -3,6 +3,7 @@ import os import sys +from django.core.cache import cache from django.core.files.storage import storages from django.db import models from django.http import HttpResponse @@ -30,7 +31,14 @@ def create_module(self, spec): return None # Use default module creation def exec_module(self, module): - storage = storages.create_storage(storages.backends["scripts"]) + # Cache storage for 5 minutes (300 seconds) + cache_key = "storage_scripts" + storage = cache.get(cache_key) + + if storage is None: + storage = storages['scripts'] + cache.set(cache_key, storage, timeout=300) # 5 minutes + with storage.open(self.filename, 'rb') as f: code = f.read() exec(code, module.__dict__)