opnsense / core

OPNsense GUI, API and systems backend
https://opnsense.org/
BSD 2-Clause "Simplified" License
3.28k stars 727 forks source link

configd: add cache option to configd script_output commands #7515

Closed AdSchellevis closed 3 months ago

AdSchellevis commented 3 months ago

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

Is your feature request related to a problem? Please describe.

Currently we offer caching in JsonKeyValueStoreField types when used in the model, but these aren't very generic and expect their own temp file organization. It would be practical to offer a generic (optional) cache TTL flag in configd script output commands, as the results offered in these fields are usually pretty stale and other callers could use the same cache.

The are some other commands that could use a bit of cache like searching the state table, which would be annoying to add specifically for these commands.

Describe the solution you like

a cache_ttl property which can be added to a script output command. If we make sure cache always invalidates while configd has not been restarted, we don't risk any stickyness over upgrades.

Describe alternatives you considered

Add a cache on the current state table parsing command, which is less clean and duplicates more code than we would like to see.

Additional context

Candidates which could mode the cache attributes to configd:

https://github.com/opnsense/core/blob/0dc1f2186af1dd8d74dafafac91faccc58ad18f1/src/opnsense/mvc/app/models/OPNsense/Core/Hasync.xml#L41-L48

https://github.com/opnsense/core/blob/0dc1f2186af1dd8d74dafafac91faccc58ad18f1/src/opnsense/mvc/app/models/OPNsense/Routes/Route.xml#L11-L17

https://github.com/opnsense/core/blob/0dc1f2186af1dd8d74dafafac91faccc58ad18f1/src/opnsense/mvc/app/models/OPNsense/Syslog/Syslog.xml#L38-L45

https://github.com/opnsense/core/blob/0dc1f2186af1dd8d74dafafac91faccc58ad18f1/src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.xml#L87-L92