{"id":34036678,"url":"https://github.com/gqylpy/funccache","last_synced_at":"2026-04-09T04:04:59.115Z","repository":{"id":61544483,"uuid":"496168327","full_name":"gqylpy/funccache","owner":"gqylpy","description":"True to its name, `funccache` implements the cache function. Cache the return value of a callable object or all methods defined in a class.","archived":false,"fork":false,"pushed_at":"2024-10-10T01:13:35.000Z","size":51,"stargazers_count":91,"open_issues_count":4,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-13T17:25:25.404Z","etag":null,"topics":["function-cache","gqylpy","python"],"latest_commit_sha":null,"homepage":"http://gqylpy.com","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/gqylpy.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}},"created_at":"2022-05-25T09:38:19.000Z","updated_at":"2026-01-09T23:41:06.000Z","dependencies_parsed_at":"2024-04-15T02:26:59.867Z","dependency_job_id":"fe6948bf-f718-4939-bafe-8da06fb07683","html_url":"https://github.com/gqylpy/funccache","commit_stats":{"total_commits":26,"total_committers":3,"mean_commits":8.666666666666666,"dds":0.5,"last_synced_commit":"dcc078b9dfcf58348ca52638dcf52334f551746b"},"previous_names":["gqylpy/gqylpy-cache"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/gqylpy/funccache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gqylpy%2Ffunccache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gqylpy%2Ffunccache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gqylpy%2Ffunccache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gqylpy%2Ffunccache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gqylpy","download_url":"https://codeload.github.com/gqylpy/funccache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gqylpy%2Ffunccache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31584834,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"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":["function-cache","gqylpy","python"],"created_at":"2025-12-13T20:37:26.181Z","updated_at":"2026-04-09T04:04:59.111Z","avatar_url":"https://github.com/gqylpy.png","language":"Python","readme":"[\u003cimg alt=\"LOGO\" src=\"https://python.org/favicon.ico\" height=\"21\" width=\"21\"/\u003e](http://gqylpy.com)\n[![Release](https://img.shields.io/github/release/gqylpy/funccache.svg?style=flat-square\")](https://github.com/gqylpy/funccache/releases/latest)\n[![Python Versions](https://img.shields.io/pypi/pyversions/funccache)](https://pypi.org/project/funccache)\n[![License](https://img.shields.io/pypi/l/funccache)](https://github.com/gqylpy/funccache/blob/master/LICENSE)\n[![Downloads](https://static.pepy.tech/badge/funccache)](https://pepy.tech/project/funccache)\n\n# funccache\nEnglish | [中文](https://github.com/gqylpy/funccache/blob/master/README_CN.md)\n\n`funccache`, as its name suggests, is a framework developed by the GQYLPY team that implements function caching. It can cache the return values of specific functions or all methods defined within a class.\n\n\u003e _What if you have a function in your program that gets called multiple times and always returns the same value? To improve code efficiency, you might call the function once, store the return value in a variable, and then use that variable instead of repeatedly calling the function. Sound familiar? That's great! But now, we're here to introduce a more elegant solution: using the `funccache` module to directly cache function return values._\n\n`funccache` can be used in two ways: as a metaclass to cache the return values of all methods defined in its metaclass instances, or as a decorator to cache the return values of decorated functions.\n\n\u003ckbd\u003epip3 install funccache\u003c/kbd\u003e\n\n### Caching Return Values of Class Methods\n\n```python\nimport funccache\n\nclass Alpha(metaclass=funccache):\n    ...\n```\nIn this case, all methods and `property` attributes defined in the `Alpha` class will have their return values cached in the `__cache_pool__` attribute after being called once by an instance of the class. Subsequent calls, as long as the parameters remain the same, will directly retrieve values from `__cache_pool__` without re-executing the related code, significantly reducing program overhead and improving code readability.\n\nBy default, this caching functionality only applies to individual instances, and each instance has its own `__cache_pool__` attribute. However, if you want all instances of `Alpha` to share the same cache, you can enable the `__shared_instance_cache__` attribute:\n```python\nclass Alpha(metaclass=funccache):\n    __shared_instance_cache__ = True\n```\nSetting the class attribute `__shared_instance_cache__ = True` creates the `__cache_pool__` attribute in the `Alpha` class itself, rather than in each individual instance of `Alpha`.\n\nThe cache never expires by default, but you can set a time-to-live (TTL) for the cache using the class attribute `__ttl__`:\n```python\nclass Alpha(metaclass=funccache):\n    __ttl__ = 60\n```\n\nIf you want a specific method or `property` to not be cached, you can add it to the `__not_cache__` list:\n\n```python\nclass Alpha(metaclass=funccache):\n    __not_cache__ = [method_obj_or_method_name, ...]\n```\nAdditionally, subclasses of `Alpha` will also inherit the caching functionality.\n\n### Caching Return Values of Functions\n\n```python\nimport funccache\n\n@funccache\ndef alpha():\n    ...\n```\nIn this case, the return value of the `alpha` function will be cached after it is called once. Subsequent calls, as long as the parameters remain the same, will directly retrieve the value from the cache without re-executing the `alpha` function.\n\nThe cache never expires by default, but if you want the cache to expire after a certain period, you can use `funccache.ttl`:\n```python\n@funccache.ttl(60)\ndef alpha():\n    ...\n```\n\nYou can even cache based on the number of calls using `funccache.count`:\n```python\n@funccache.count(3)\ndef alpha():\n    ...\n```\n\nThe decorator usage can also achieve singleton class behavior, as long as the instantiation parameters are consistent:\n```python\n@funccache\nclass Alpha:\n    ...\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgqylpy%2Ffunccache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgqylpy%2Ffunccache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgqylpy%2Ffunccache/lists"}