{"id":41435675,"url":"https://github.com/ecmwf-projects/cacholote","last_synced_at":"2026-01-23T14:37:34.112Z","repository":{"id":46239782,"uuid":"221898877","full_name":"ecmwf-projects/cacholote","owner":"ecmwf-projects","description":"Efficiently cache calls to functions","archived":false,"fork":false,"pushed_at":"2025-09-19T15:48:07.000Z","size":406,"stargazers_count":9,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-09-19T17:46:05.789Z","etag":null,"topics":["cads"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecmwf-projects.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-11-15T10:17:19.000Z","updated_at":"2025-09-19T15:48:10.000Z","dependencies_parsed_at":"2023-10-26T11:39:51.221Z","dependency_job_id":"580d09d5-ebf3-4b68-a053-d2d68e749bb0","html_url":"https://github.com/ecmwf-projects/cacholote","commit_stats":{"total_commits":312,"total_committers":3,"mean_commits":104.0,"dds":"0.15384615384615385","last_synced_commit":"f1a03a1d9fc0d5e6b75562818973aabd13500c60"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"purl":"pkg:github/ecmwf-projects/cacholote","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecmwf-projects%2Fcacholote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecmwf-projects%2Fcacholote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecmwf-projects%2Fcacholote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecmwf-projects%2Fcacholote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecmwf-projects","download_url":"https://codeload.github.com/ecmwf-projects/cacholote/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecmwf-projects%2Fcacholote/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28694451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T14:15:13.573Z","status":"ssl_error","status_checked_at":"2026-01-23T14:09:05.534Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cads"],"created_at":"2026-01-23T14:37:33.447Z","updated_at":"2026-01-23T14:37:34.103Z","avatar_url":"https://github.com/ecmwf-projects.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cacholote\n\nEfficiently cache calls to functions\n\n## Quick Start\n\n```python\n\u003e\u003e\u003e import cacholote\n\u003e\u003e\u003e cacholote.config.set(cache_db_urlpath=\"sqlite://\")\n\u003ccacholote.config.set ...\n\n\u003e\u003e\u003e @cacholote.cacheable\n... def now():\n...     import datetime\n...\n...     return datetime.datetime.now()\n...\n\n\u003e\u003e\u003e now() == now()\nTrue\n\n\u003e\u003e\u003e with cacholote.config.set(use_cache=False):\n...     now() == now()\n...\nFalse\n\n```\n\n### Cache files\n\n```python\n\u003e\u003e\u003e import cacholote\n\n\u003e\u003e\u003e import tempfile\n\u003e\u003e\u003e tmpdir = tempfile.TemporaryDirectory().name\n\u003e\u003e\u003e cacholote.config.set(\n...     cache_db_urlpath=\"sqlite://\",\n...     cache_files_urlpath=tmpdir,\n... )\n\u003ccacholote.config.set ...\n\n\u003e\u003e\u003e cached_open = cacholote.cacheable(open)\n\u003e\u003e\u003e cached_file = cached_open(\"README.md\")\n\u003e\u003e\u003e cached_file.name.startswith(tmpdir)\nTrue\n\n\u003e\u003e\u003e import filecmp\n\u003e\u003e\u003e filecmp.cmp(\"README.md\", cached_file.name)\nTrue\n\n```\n\n### Cache Xarray objects\n\n```python\n\u003e\u003e\u003e import cacholote\n\n\u003e\u003e\u003e import pytest\n\u003e\u003e\u003e xr = pytest.importorskip(\"xarray\")\n\n\u003e\u003e\u003e import tempfile\n\u003e\u003e\u003e tmpdir = tempfile.TemporaryDirectory().name\n\u003e\u003e\u003e cacholote.config.set(\n...     cache_db_urlpath=\"sqlite://\",\n...     cache_files_urlpath=tmpdir,\n... )\n\u003ccacholote.config.set ...\n\n\u003e\u003e\u003e @cacholote.cacheable\n... def dataset_from_dict(ds_dict):\n...     return xr.Dataset(ds_dict)\n...\n\n\u003e\u003e\u003e ds = dataset_from_dict({\"foo\": 0})\n\u003e\u003e\u003e ds\n\u003cxarray.Dataset\u003e Size: 8B\nDimensions:  ()\nData variables:\n    foo      int64 ...\n\n\u003e\u003e\u003e ds.encoding[\"source\"].startswith(tmpdir)\nTrue\n\n```\n\n## Configuration\n\nConfiguration settings can be accessed using `cacholote.config.get()` and modified using `cacholote.config.set(**kwargs)`. It is possible to use `cacholote.config.set` either as a context manager, or to configure global settings. See `help(cacholote.config.set)`.\n\nDefaults are controlled by environment variables and dotenv files. See `help(cacholote.config.reset)`.\n\n## Workflow for developers/contributors\n\nFor best experience create a new conda environment (e.g. DEVELOP) with Python 3.12:\n\n```\nconda create -n DEVELOP -c conda-forge python=3.12\nconda activate DEVELOP\n```\n\nBefore pushing to GitHub, run the following commands:\n\n1. Update conda environment: `make conda-env-update`\n1. Install this package: `pip install -e .`\n1. Sync with the latest [template](https://github.com/ecmwf-projects/cookiecutter-conda-package) (optional): `make template-update`\n1. Run quality assurance checks: `make qa`\n1. Run tests: `make unit-tests`\n1. Run the static type checker: `make type-check`\n1. Build the documentation (see [Sphinx tutorial](https://www.sphinx-doc.org/en/master/tutorial/)): `make docs-build`\n\n### Instructions for creating a new database version\n\nIn case of database structure upgrade, developers must follow these steps:\n\n1. Update the new database structure modifying [/cacholote/database.py](/cacholote/database.py), using\n   [SQLAlchemy ORM technologies](https://docs.sqlalchemy.org/en/latest/orm/)\n1. Execute from the cacholote work folder:\n   ```\n   alembic revision -m \"message about the db modification\"\n   ```\n1. The last command will create a new python file inside [/alembic/versions](/alembic/versions). Fill the `upgrade`\n   function with the operations that must be executed to migrate the database from the old structure to the new one.\n   Keep in mind both DDL (structure modification) and DML (data modification) instructions. For reference,\n   use https://alembic.sqlalchemy.org/en/latest/ops.html#ops.\n   Similarly, do the same with the `downgrade` function.\n1. Commit and push the modifications and the new file.\n\n### Instructions for moving between different database versions\n\nThe package comes with its own 'cacholote-alembic-cli' script in order to move between different\ndatabase versions. This script is a slight modified version of the 'alembic' script, overriding\ndefault config path used ([cacholote/alembic.ini](/cacholote/alembic.ini)) and the sqlalchemy.url used, that is\nautomatically computed by the environment and not read from any ini file.\n\nAll the database releases where you can migrate up and down must be defined by files contained inside\nthe folder [/cacholote/alembic/versions](/cacholote/alembic/versions). All these files are in a version queue: each file has\nlink to its revision hash (variable 'revision', the prefix of the file name) and to the next older one\n(variable 'down_revision'), and contains code to step up and down that database version.\\\nSome useful commands are listed below.\n\n- To migrate to the newest version, type:\\\n  `cacholote-alembic-cli upgrade head`\n- To upgrade to a specific version hash, for example 8ccbe515155c, type:\\\n  `cacholote-alembic-cli upgrade 8ccbe515155c`\n- To downgrade to a specific version hash, for example 8ccbe515155c, type:\\\n  `cacholote-alembic-cli downgrade 8ccbe515155c`\n- To get the current version hash of the database, type:\\\n  `cacholote-alembic-cli current`\n\nDatabase migration changes could be applied to the cacholote component of the database, too. In such case,\nmigrate the cacholote component after the migration by the 'broker-alembic-cli' tool.\n\nOther details are the same of the standard alembic migration tool,\nsee the [Alembic tutorial](https://alembic.sqlalchemy.org/en/latest/tutorial.html).\n\nFor details about the alembic migration tool, see the [Alembic tutorial](https://alembic.sqlalchemy.org/en/latest/tutorial.html).\n\n## License\n\n```\nCopyright 2019, B-Open Solutions srl.\nCopyright 2022, European Union.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecmwf-projects%2Fcacholote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecmwf-projects%2Fcacholote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecmwf-projects%2Fcacholote/lists"}