{"id":15493823,"url":"https://github.com/peter554/contextcache","last_synced_at":"2026-06-09T11:31:28.406Z","repository":{"id":200845988,"uuid":"706374345","full_name":"Peter554/contextcache","owner":"Peter554","description":"Cache a python function, only in certain contexts","archived":false,"fork":false,"pushed_at":"2023-10-19T21:32:40.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-05T13:34:30.615Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Peter554.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-10-17T20:26:10.000Z","updated_at":"2023-10-17T21:20:52.000Z","dependencies_parsed_at":"2023-10-19T23:19:02.454Z","dependency_job_id":null,"html_url":"https://github.com/Peter554/contextcache","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"7b9ee12eb6d8b201d13e41db4f5a03cb561c27b4"},"previous_names":["peter554/contextcache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Peter554/contextcache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peter554%2Fcontextcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peter554%2Fcontextcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peter554%2Fcontextcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peter554%2Fcontextcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Peter554","download_url":"https://codeload.github.com/Peter554/contextcache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peter554%2Fcontextcache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34105565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-02T08:09:32.279Z","updated_at":"2026-06-09T11:31:28.380Z","avatar_url":"https://github.com/Peter554.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# contextcache\n\n[![CI](https://github.com/Peter554/contextcache/actions/workflows/ci.yml/badge.svg)](https://github.com/Peter554/contextcache/actions/workflows/ci.yml)\n\nCache a python function *only in certain contexts*.\n\n## Usage\n\nHere's an example:\n\n```sh\ncat example.py     \n```\n        \n```py\nimport contextcache\n\n# Define a private CacheContextVar to store the cached values.\n# Don't touch this CacheContextVar from anywhere else!\n# You need to define a separate CacheContextVar for every function for which\n# you want to enable caching. Use `None` as the default.\n_double_cache = contextcache.CacheContextVar(\"double_cache\", default=None)\n\n\n# Use the `enable_caching` decorator to enable context caching for `double`.\n@contextcache.enable_caching(_double_cache)\ndef double(n: int) -\u003e int:\n    print(f\"Doubling {n}, working...\")\n    return n * 2\n\n\n# Without caching.\nprint(\"Without caching\")\nprint(double(1))\nprint(double(1))\n\n# With caching.\nwith contextcache.use_caching(double):\n    print(\"\\nWith caching\")\n    print(double(1))\n    print(double(1))\n\n# Without caching, again.\nprint(\"\\nWithout caching, again\")\nprint(double(1))\nprint(double(1))\n```\n\nHere's the output:\n\n```sh\npython example.py\n```\n\n```\nWithout caching\nDoubling 1, working...\n2\nDoubling 1, working...\n2\n\nWith caching\nDoubling 1, working...\n2\n2\n\nWithout caching, again\nDoubling 1, working...\n2\nDoubling 1, working...\n2\n```\n\nSee the tests for further examples.\n\n## Caveats\n\n* Function arguments must be hashable.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter554%2Fcontextcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeter554%2Fcontextcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter554%2Fcontextcache/lists"}