qcc_kplugin.qcache ================== .. py:module:: qcc_kplugin.qcache .. autoapi-nested-parse:: Cache and background loading of the slow ``qcc components …`` queries (list, parameters, outline). Each call starts Python and imports the library (~1.4 s). Called synchronously from the panel that froze KLayout, so: * results are cached in memory and in one JSON file in the temp folder (so the next KLayout start is instant too); * the cache is valid for one *library key*: the ``qcc`` path and time, and the newest modification time under ``src/quantcore_circuits/layouts`` when the plugin runs from the repository. A library change refreshes everything; * :func:`fetch` runs a query in a subprocess polled from a timer and calls ``done(data)`` when it is there, at once when the result is cached. ``data`` is ``None`` when ``qcc`` failed. Names used by the panel: ``list:``, ``schema:``, ``outline::``, plus the bulk ``schemas:quantcore`` that fills every ``schema:`` in one call (prefetch). Attributes ---------- .. autoapisummary:: qcc_kplugin.qcache.CACHE_FILE qcc_kplugin.qcache.LAYOUTS qcc_kplugin.qcache.PENDING Functions --------- .. autoapisummary:: qcc_kplugin.qcache.clear qcc_kplugin.qcache.fetch qcc_kplugin.qcache.get qcc_kplugin.qcache.library_key qcc_kplugin.qcache.loads_tolerant qcc_kplugin.qcache.outline_key qcc_kplugin.qcache.poll qcc_kplugin.qcache.put qcc_kplugin.qcache.schema_key qcc_kplugin.qcache.wait Module Contents --------------- .. py:function:: clear() -> None Forget everything (the panel's Refresh list). .. py:function:: fetch(name: str, args: list[str], done=None, bulk: bool = False) -> None ``done(data)`` with the JSON of ``qcc *args`` — at once when ``name`` is cached, else after the background run. .. py:function:: get(name: str) The cached value of ``name`` (None when absent or from another library version). .. py:function:: library_key() -> str qcc path + its mtime + newest mtime of the library sources (re-evaluated at most every 2 s). .. py:function:: loads_tolerant(text: str) ``json.loads`` for what a ``qcc`` call printed. Some Quantum Metal calls print a warning line on stdout before the JSON (``FutureWarning: ...``): then the JSON is the last line that starts with ``{`` or ``[``. .. py:function:: outline_key(cell: str, params_json: str) -> str .. py:function:: poll() -> bool Collect the finished queries and call their callbacks; True while something still runs. .. py:function:: put(name: str, value, save: bool = True) -> None .. py:function:: schema_key(cell: str) -> str .. py:function:: wait(timeout: float = 60.0) -> None Block until nothing is pending (tests only). .. py:data:: CACHE_FILE .. py:data:: LAYOUTS .. py:data:: PENDING :type: dict[str, dict]