# ff-cache
一个简洁易用的 cache 封装库。
## 主要功能
- 通过注解`cache`来对函数执行结果进行缓存处理
- 支持对缓存进行标签分组管理
- 支持 memory / redis 缓存
- 支持自定义缓存逻辑(缓存key、根据结果动态计算缓存时间)
## 安装
```bash
pip install ff-cache
```
## 快速开始
```python
from ff_cache import ContextManager, MemoryCache, cache
from ff_cache.redis import RedisCache
redis_url = "redis://localhost:6379/0"
ContextManager.init(cache=RedisCache(url=redis_url))
@cache()
def hello_world():
"""
"""
print("function executed.")
return "hello world"
if __name__ == '__main__':
print(hello_world()) # 第一次执行,控制台打印出:function executed.
print("---------------------------------")
print(hello_world()) # 第二次执行,控制台没有打印:function executed. 说明缓存成功
```
## 更多示例
请参考 `tests` 目录下的用例。
## 贡献指南
欢迎提交 Issue 或 PR,完善功能或修复问题。请确保代码风格与项目保持一致,并补充必要的测试。
## License
MIT
Raw data
{
"_id": null,
"home_page": "https://github.com/itsanr-oris/ff-cache",
"name": "ff-cache",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "cache, redis-cache",
"author": "foris.feng",
"author_email": "us@f-oris.me",
"download_url": "https://files.pythonhosted.org/packages/ce/dd/d972989a64a922425fbcbab156cb0f7ec56865ffac552919c457940e48a6/ff_cache-0.2.0.tar.gz",
"platform": null,
"description": "# ff-cache\n\n\u4e00\u4e2a\u7b80\u6d01\u6613\u7528\u7684 cache \u5c01\u88c5\u5e93\u3002\n\n## \u4e3b\u8981\u529f\u80fd\n\n- \u901a\u8fc7\u6ce8\u89e3`cache`\u6765\u5bf9\u51fd\u6570\u6267\u884c\u7ed3\u679c\u8fdb\u884c\u7f13\u5b58\u5904\u7406\n- \u652f\u6301\u5bf9\u7f13\u5b58\u8fdb\u884c\u6807\u7b7e\u5206\u7ec4\u7ba1\u7406\n- \u652f\u6301 memory / redis \u7f13\u5b58\n- \u652f\u6301\u81ea\u5b9a\u4e49\u7f13\u5b58\u903b\u8f91(\u7f13\u5b58key\u3001\u6839\u636e\u7ed3\u679c\u52a8\u6001\u8ba1\u7b97\u7f13\u5b58\u65f6\u95f4)\n\n## \u5b89\u88c5\n\n```bash\npip install ff-cache\n```\n\n## \u5feb\u901f\u5f00\u59cb\n\n```python\nfrom ff_cache import ContextManager, MemoryCache, cache\nfrom ff_cache.redis import RedisCache\n\n\nredis_url = \"redis://localhost:6379/0\"\nContextManager.init(cache=RedisCache(url=redis_url))\n\n@cache()\ndef hello_world():\n \"\"\"\n \"\"\"\n print(\"function executed.\")\n return \"hello world\"\n\n\nif __name__ == '__main__':\n print(hello_world()) # \u7b2c\u4e00\u6b21\u6267\u884c\uff0c\u63a7\u5236\u53f0\u6253\u5370\u51fa\uff1afunction executed.\n print(\"---------------------------------\")\n print(hello_world()) # \u7b2c\u4e8c\u6b21\u6267\u884c\uff0c\u63a7\u5236\u53f0\u6ca1\u6709\u6253\u5370\uff1afunction executed. \u8bf4\u660e\u7f13\u5b58\u6210\u529f\n```\n\n## \u66f4\u591a\u793a\u4f8b\n\n\u8bf7\u53c2\u8003 `tests` \u76ee\u5f55\u4e0b\u7684\u7528\u4f8b\u3002\n\n## \u8d21\u732e\u6307\u5357\n\n\u6b22\u8fce\u63d0\u4ea4 Issue \u6216 PR\uff0c\u5b8c\u5584\u529f\u80fd\u6216\u4fee\u590d\u95ee\u9898\u3002\u8bf7\u786e\u4fdd\u4ee3\u7801\u98ce\u683c\u4e0e\u9879\u76ee\u4fdd\u6301\u4e00\u81f4\uff0c\u5e76\u8865\u5145\u5fc5\u8981\u7684\u6d4b\u8bd5\u3002\n\n## License\n\nMIT\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple cache library.",
"version": "0.2.0",
"project_urls": {
"Bug Tracker": "https://github.com/itsanr-oris/ff-cache/issues",
"Homepage": "https://github.com/itsanr-oris/ff-cache",
"Source Code": "https://github.com/itsanr-oris/ff-cache"
},
"split_keywords": [
"cache",
" redis-cache"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f9dd7c13f0f42a0927a81bc6e722b61e42d2d16e7e39ef6326e453263fec55f0",
"md5": "43e026be5b162d8f06edd83c13a0dc1f",
"sha256": "b7c78d03944435e2f3fafde47f5bb74c5e8b2bec48c8bc8ce6e5aef7d0107fc9"
},
"downloads": -1,
"filename": "ff_cache-0.2.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "43e026be5b162d8f06edd83c13a0dc1f",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.6",
"size": 12094,
"upload_time": "2025-09-18T16:22:56",
"upload_time_iso_8601": "2025-09-18T16:22:56.865943Z",
"url": "https://files.pythonhosted.org/packages/f9/dd/7c13f0f42a0927a81bc6e722b61e42d2d16e7e39ef6326e453263fec55f0/ff_cache-0.2.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ceddd972989a64a922425fbcbab156cb0f7ec56865ffac552919c457940e48a6",
"md5": "b6c6fd8ed0519fea2870f471cedc8b92",
"sha256": "0a8234048a524e5c8e53c643795e2f27b4fdc5f7c0d8362ae1b7d8a45cec65bf"
},
"downloads": -1,
"filename": "ff_cache-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "b6c6fd8ed0519fea2870f471cedc8b92",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 10259,
"upload_time": "2025-09-18T16:22:58",
"upload_time_iso_8601": "2025-09-18T16:22:58.308510Z",
"url": "https://files.pythonhosted.org/packages/ce/dd/d972989a64a922425fbcbab156cb0f7ec56865ffac552919c457940e48a6/ff_cache-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-18 16:22:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "itsanr-oris",
"github_project": "ff-cache",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "tox",
"specs": []
},
{
"name": "twine",
"specs": []
},
{
"name": "tox-conda",
"specs": []
},
{
"name": "faker",
"specs": []
},
{
"name": "pytest",
"specs": []
},
{
"name": "pytest-cov",
"specs": []
},
{
"name": "pytest-asyncio",
"specs": []
},
{
"name": "redis",
"specs": [
[
">=",
"4.2.0"
]
]
},
{
"name": "deprecated",
"specs": []
}
],
"tox": true,
"lcname": "ff-cache"
}