{"id":20636739,"url":"https://github.com/libcommon/cache-py","last_synced_at":"2026-06-01T04:01:44.169Z","repository":{"id":62575334,"uuid":"221384782","full_name":"libcommon/cache-py","owner":"libcommon","description":"Python library containing simple implementations of caches.","archived":false,"fork":false,"pushed_at":"2022-12-26T21:31:03.000Z","size":41,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-19T12:27:58.616Z","etag":null,"topics":["cache","library","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libcommon.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}},"created_at":"2019-11-13T06:05:32.000Z","updated_at":"2020-05-12T05:50:48.000Z","dependencies_parsed_at":"2023-01-31T01:45:47.532Z","dependency_job_id":null,"html_url":"https://github.com/libcommon/cache-py","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/libcommon/cache-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libcommon%2Fcache-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libcommon%2Fcache-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libcommon%2Fcache-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libcommon%2Fcache-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libcommon","download_url":"https://codeload.github.com/libcommon/cache-py/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libcommon%2Fcache-py/sbom","scorecard":{"id":587810,"data":{"date":"2025-08-11","repo":{"name":"github.com/libcommon/cache-py","commit":"2f34ce8b547ff6dde175e7e02456a7a2133926b7"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.9,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/15 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2022-43017 / GHSA-qwmp-2cf2-g9g6"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T21:03:05.664Z","repository_id":62575334,"created_at":"2025-08-20T21:03:05.664Z","updated_at":"2025-08-20T21:03:05.664Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33759178,"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-01T02:00:06.963Z","response_time":115,"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":["cache","library","python"],"created_at":"2024-11-16T15:12:01.188Z","updated_at":"2026-06-01T04:01:44.149Z","avatar_url":"https://github.com/libcommon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cache-py\n\n## Overview\n\nCaches are useful as temporary, fast-access datastores for API responses, data computed with complex calculations, and\nany other kind of data that's relatively expensive to retrieve/compute. `cache-py` is a Python library consisting of\na simple cache interface (base class), implementations of common caches using this interface, and a general purpose\nhashing function for Python objects. All implementations are currently local and in-memory, though one could easily use the interface\nto implement file or API-based caches.\n\n## Installation\n\n### Install from PyPi (preferred method)\n\n```bash\npip install lc-cache\n```\n\n### Install from GitHub with Pip\n\n```bash\npip install git+https://github.com/libcommon/cache-py.git@vx.x.x#egg=lc_cache\n```\n\nwhere `x.x.x` is the version you want to download.\n\n## Install by Manual Download\n\nTo download the source distribution and/or wheel files, navigate to\n`https://github.com/libcommon/cache-py/tree/releases/vx.x.x/dist`, where `x.x.x` is the version you want to install,\nand download either via the UI or with a tool like wget. Then to install run:\n\n```bash\npip install \u003cdownloaded file\u003e\n```\n\nDo _not_ change the name of the file after downloading, as Pip requires a specific naming convention for installation files.\n\n## Dependencies\n\n`cache-py` does not have external dependencies. Only Python versions \u003e= 3.6 are officially supported.\n\n## Getting Started\n\nIf you simply need to store values and later check for their presence, but don't necessarily care about retrieving the values themselves, use the `HashsetCache`.\n\n```python\nimport random\n\nfrom lc_cache import HashsetCache\n\ndef main() -\u003e int:\n    # Create the cache\n    cache = HashsetCache()\n\n    # Insert some random values into the cache\n    for _ in range(10):\n        cache.insert(random.randrange(0, 10))\n        \n    # Check for their presence\n    for i in range(10):\n        if cache.check(i):\n            print(\"Encountered value\", i)\n\n    return 0\n```\n\nIf you need to retrieve values later on, and have a key to associate them with, use the `HashmapCache`. Below is an implementation\nof `functools.lru_cache`, though it is simply a reference. Do not use this implementation as it is not thread-safe, and\nthe `functools` version has some optimizations that likely make it faster.\n\n```python\nfrom functools import wraps\nfrom typing import Any, Callable\n\nfrom lc_cache import HashmapCache, gen_python_hash\n\n_CACHE = HashmapCache()\n\ndef lru_cache(f: Callable[..., Any]) -\u003e Callable[..., Any]:\n    @wraps(f)\n    def wrapper(*args, **kwargs) -\u003e Any:\n        args_hash = hash((gen_python_hash(args), gen_python_hash(kwargs)))\n        # NOTE: Have to use check here because a cached value may be None\n        if _CACHE.check(args_hash):\n            return _CACHE.get(args_hash)\n        return f(*args, **kwargs)\n    return wrapper\n```\n\nThe `SizedHashmapCache` and `SizedLRUCache` classes may be useful in long-running processes where you want to cap the\nnumber of items in the cache.\n\n## Use Case\n\nThe cache interface class, `Cache`, defines a simple API for manipulating the underlying storage object(s):\n\n    * `check`: check if a value is present in the cache\n    * `insert`: add a value to the cache, or update an existing one\n    * `get`: get a value from the cache, if it exists\n    * `remove`: remove a value from the cache, if it exists\n    * `clear`: clear the cache\n    * `iter`: returns a [Generator](https://wiki.python.org/moin/Generators) over the values in the dictionary\n\nNote that the word \"value\" here is used loosely, and does not refer to a value in a Python dictionary.  That being said,\nPython dictionaries are commonly used to cache values. The `HashmapCache` has a regular Python dictionary as the underlying\nstorage object, and thus can be used just like a dictionary. Similarly, The `SizedHashmapCache` and `SizedLRUCache` cache\nclasses are also backed by dictionaries, but with some extra constraints on cache size and logic for removing items.\n\nIf your use case isn't complicated, and a simple dictionary will suffice, then there's no need to use classes from this library.\nHowever, if you need something like an LRU cache, or if you're developing an MVP but will need a more complex cache implementation\nlater on (and thus want a consistent API), this library can be helpful.\n\n## Contributing/Suggestions\n\nContributions and suggestions are welcome! To make a feature request, report a bug, or otherwise comment on existing\nfunctionality, please [file an issue](https://github.com/libcommon/cache-py/issues/new/choose). For contributions please\n[submit a PR](https://github.com/libcommon/cache-py/compare), but make sure to lint, type-check, and test your code\nbefore doing so. Thanks in advance!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibcommon%2Fcache-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibcommon%2Fcache-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibcommon%2Fcache-py/lists"}