{"action":"opened","issue":{"url":"https://api.github.com/repos/python-ivi/python-ivi/issues/43","labels_url":"https://api.github.com/repos/python-ivi/python-ivi/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/python-ivi/python-ivi/issues/43/comments","events_url":"https://api.github.com/repos/python-ivi/python-ivi/issues/43/events","html_url":"https://github.com/python-ivi/python-ivi/issues/43","id":119035546,"number":43,"title":"Improve cache handling","user":{"login":"herm","id":753225,"avatar_url":"https://avatars.githubusercontent.com/u/753225?v=3","gravatar_id":"","url":"https://api.github.com/users/herm","html_url":"https://github.com/herm","followers_url":"https://api.github.com/users/herm/followers","following_url":"https://api.github.com/users/herm/following{/other_user}","gists_url":"https://api.github.com/users/herm/gists{/gist_id}","starred_url":"https://api.github.com/users/herm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/herm/subscriptions","organizations_url":"https://api.github.com/users/herm/orgs","repos_url":"https://api.github.com/users/herm/repos","events_url":"https://api.github.com/users/herm/events{/privacy}","received_events_url":"https://api.github.com/users/herm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-26T12:26:55Z","updated_at":"2015-11-26T12:26:55Z","closed_at":null,"body":"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.\r\n\r\nThis very long code\r\n```\r\n    def _get_trigger_delay(self):\r\n        if not self._driver_operation_simulate and not self._get_cache_valid():\r\n            value = float(self._ask(\"trigger:delay?\"))\r\n            self._trigger_delay = value\r\n            self._set_cache_valid()\r\n        return self._trigger_delay\r\n    \r\n    def _set_trigger_delay(self, value):\r\n        value = float(value)\r\n        if not self._driver_operation_simulate:\r\n            self._write('trigger:delay %g' % value)\r\n        self._trigger_delay = value\r\n        self._set_cache_valid()\r\n``` \r\nbecomes\r\n```\r\n    @cacheable\r\n    def _get_trigger_delay(self):\r\n        return value = float(self._ask(\"trigger:delay?\"))\r\n\r\n    @cacheable    \r\n    def _set_trigger_delay(self, value):\r\n        self._write('trigger:delay %g' % value)\r\n```\r\nWhich 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. \r\nCode:  https://gist.github.com/herm/9e9d02218f5a1dddd8d9\r\n\r\n"}}