# aiomemoizettl [](https://circleci.com/gh/michalc/aiomemoizettl) [](https://codeclimate.com/github/michalc/aiomemoizettl/test_coverage)
Memoize asyncio Python calls with a per-result TTL
## Installation
```base
pip install aiomemoizettl
```
## Usage
For a coroutine whose arguments are hashable, you can create a _memoized_ version by passing it to `memoize_ttl`, along with a function that converts its return value to a TTL.
For example, the below
```python
import asyncio
from aiomemoizettl import memoize_ttl
async def main():
memoized = memoize_ttl(coro, get_ttl=lambda result: result['ttl'])
results = await asyncio.gather(*[
memoized(1),
memoized(2),
])
await asyncio.sleep(1)
results = await asyncio.gather(*[
memoized(1),
memoized(2), # Will used the cached value of `coro(2)`
])
async def coro(value):
print('Inside coro', value)
return {'ttl': value, 'some-other': 'data'}
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
```
will output
```
Inside coro 1
Inside coro 2
Inside coro 1
```
Raw data
{
"_id": null,
"home_page": "https://github.com/michalc/aiomemoizettl",
"name": "aiomemoizettl",
"maintainer": "",
"docs_url": null,
"requires_python": "~=3.5",
"maintainer_email": "",
"keywords": "",
"author": "Michal Charemza",
"author_email": "michal@charemza.name",
"download_url": "https://files.pythonhosted.org/packages/3f/6d/e57e96f11ee334ec746b4d7a96351b35f6b42e53855c2a7c255d16be62e3/aiomemoizettl-0.0.3.tar.gz",
"platform": "",
"description": "# aiomemoizettl [](https://circleci.com/gh/michalc/aiomemoizettl) [](https://codeclimate.com/github/michalc/aiomemoizettl/test_coverage)\n\nMemoize asyncio Python calls with a per-result TTL\n\n\n## Installation\n\n```base\npip install aiomemoizettl\n```\n\n\n## Usage\n\nFor a coroutine whose arguments are hashable, you can create a _memoized_ version by passing it to `memoize_ttl`, along with a function that converts its return value to a TTL.\n\nFor example, the below\n\n```python\nimport asyncio\nfrom aiomemoizettl import memoize_ttl\n\nasync def main():\n memoized = memoize_ttl(coro, get_ttl=lambda result: result['ttl'])\n results = await asyncio.gather(*[\n memoized(1),\n memoized(2),\n ])\n await asyncio.sleep(1)\n\n results = await asyncio.gather(*[\n memoized(1),\n memoized(2), # Will used the cached value of `coro(2)`\n ])\n\nasync def coro(value):\n print('Inside coro', value)\n return {'ttl': value, 'some-other': 'data'}\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(main())\nloop.close()\n```\n\nwill output\n\n```\nInside coro 1\nInside coro 2\nInside coro 1\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Memoize asyncio Python calls with a per-result TTL",
"version": "0.0.3",
"project_urls": {
"Homepage": "https://github.com/michalc/aiomemoizettl"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "364959ad30138158b09ee058c72d053461c15dcc3f43fe26f53fed98aab3c32e",
"md5": "4da3da0cc6b28a5e27569758367f0b57",
"sha256": "07a6becac60f6cd2604b9f2b73bcd9a50079a0b7b55e2a4e45b1eec5a3ea9659"
},
"downloads": -1,
"filename": "aiomemoizettl-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4da3da0cc6b28a5e27569758367f0b57",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.5",
"size": 3164,
"upload_time": "2019-04-05T20:42:26",
"upload_time_iso_8601": "2019-04-05T20:42:26.024928Z",
"url": "https://files.pythonhosted.org/packages/36/49/59ad30138158b09ee058c72d053461c15dcc3f43fe26f53fed98aab3c32e/aiomemoizettl-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3f6de57e96f11ee334ec746b4d7a96351b35f6b42e53855c2a7c255d16be62e3",
"md5": "13dd1cfee6bcaeb52b57ffdc4d646a17",
"sha256": "0a80d2dc765e545263f515363b6700ec8cf86fa3968b529f56390b28e34f743d"
},
"downloads": -1,
"filename": "aiomemoizettl-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "13dd1cfee6bcaeb52b57ffdc4d646a17",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.5",
"size": 2071,
"upload_time": "2019-04-05T20:42:27",
"upload_time_iso_8601": "2019-04-05T20:42:27.487338Z",
"url": "https://files.pythonhosted.org/packages/3f/6d/e57e96f11ee334ec746b4d7a96351b35f6b42e53855c2a7c255d16be62e3/aiomemoizettl-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2019-04-05 20:42:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "michalc",
"github_project": "aiomemoizettl",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"circle": true,
"lcname": "aiomemoizettl"
}