FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve cache handling · Issue #43 · python-ivi/python-ivi · GitHub

This repository was archived by the owner on Feb 2, 2026. It is now read-only.
/ python-ivi Public archive
This repository was archived by the owner on Feb 2, 2026. It is now read-only.

Improve cache handling #43

Description

Currently a lot of functions are almost identical, because they mainly consist of cache handling code. Using decorators most of this code duplication could be avoided. I implemented a demonstration for this.

This very long code

    def _get_trigger_delay(self):
        if not self._driver_operation_simulate and not self._get_cache_valid():
            value = float(self._ask("trigger:delay?"))
            self._trigger_delay = value
            self._set_cache_valid()
        return self._trigger_delay

    def _set_trigger_delay(self, value):
        value = float(value)
        if not self._driver_operation_simulate:
            self._write('trigger:delay %g' % value)
        self._trigger_delay = value
        self._set_cache_valid()

becomes

    @cacheable
    def _get_trigger_delay(self):
        return value = float(self._ask("trigger:delay?"))

    @cacheable    
    def _set_trigger_delay(self, value):
        self._write('trigger:delay %g' % value)

Which is much easier to read an less error-prone. At the moment this is just a demonstration, but if there is interest I can implement a real solution which is compatible with the current caching mechanism.
Code: https://gist.github.com/herm/9e9d02218f5a1dddd8d9

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL